Creates or configures one object property.
创建或配置一个对象属性。
Returns the object.
返回对象。
Takes 3 arguments. The first is an object upon which we’re going to create or configure the properties. The second is the property name defined as a string. The third is an object with the property definition.
接受3个参数。 第一个是我们将在其上创建或配置属性的对象。 第二个是定义为字符串的属性名称。 第三个是带有属性定义的对象。
Example:
例:
const dog = {}
Object.defineProperty(dog, 'breed', {
value: 'Siberian Husky'
})
console.log(dog.breed) //'Siberian Husky'
I didn’t just say breed: 'Siberian Husky'
but I had to pass a property descriptor object, defined at the beginning of this page.
我不只是说breed: 'Siberian Husky'
而是我必须传递在页面开头定义的属性描述符对象。
翻译自: https://flaviocopes.com/javascript-object-defineproperty/