概述
javascript @符
Any object in JavaScript has a set of properties, and each of these properties has a descriptor.
JavaScript中的任何对象都有一组属性,并且每个属性都有一个描述符 。
This is an object that defines a property behavior and own properties.
这是一个定义属性行为和自身属性的对象。
Many Object static methods interact with it. Those methods include:
许多对象静态方法与之交互。 这些方法包括:
Object.create()
Object.create()
Object.defineProperties()
Object.defineProperties()
Object.defineProperty()
Object.defineProperty()
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptors()
Object.getOwnPropertyDescriptors()
Here is an example of a property descriptor object:
这是一个属性描述符对象的示例:
{
value: 'Something'
}
This is the simplest one. value
is the property value, in a key-value definition. This key
is defined as the object key, when you define this property in an object:
这是最简单的。 value
是键值定义中的属性值。 当您在对象中定义此属性时,此key
定义为对象键:
{
breed: {
value: 'Siberian Husky'
}
}
Example:
例:
const animal = {}
const dog = Object.create(animal, {
breed: {
value: 'Siberian Husky'
}
});
console.log(dog.breed) //'Siberian Husky'
You can pass additional properties to define each different object property:
您可以传递其他属性来定义每个不同的对象属性:
value: the value of the property
值 :属性的值
writable: true the property can be changed
可写 :true可以更改属性
configurable: if false, the property cannot be removed nor any attribute can be changed, except its value
可配置的 :如果为false,则不能删除该属性,也不能更改任何属性,但其值除外
enumerable: true if the property is enumerable
枚举 :如果属性是可枚举的,则为true
get: a getter function for the property, called when the property is read
get :属性的getter函数,在读取属性时调用
set: a setter function for the property, called when the property is set to a value
set :属性的setter函数,在将属性设置为值时调用
writable
, configurable
and enumerable
set the behavior of that property. They have a boolean value, and by default those are all false
.
writable
, writable
configurable
和enumerable
设置该属性的行为。 它们具有布尔值,默认情况下均为false
。
Example:
例:
const animal = {}
const dog = Object.create(animal, {
breed: {
value: 'Siberian Husky',
writable: false
}
});
console.log(dog.breed) //'Siberian Husky'
dog.breed = 'Pug' //TypeError: Cannot assign to read only property 'breed' of object '#<Object>'
翻译自: https://flaviocopes.com/javascript-property-descriptors/
javascript @符
最后
以上就是坚定春天为你收集整理的javascript @符_JavaScript属性描述符的全部内容,希望文章能够帮你解决javascript @符_JavaScript属性描述符所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复