1. Get the property name
var o = {p1:123, p2:456}; Object.keys (o);//Get an enumerable property name//["P1", "P2"] Object.getownpropertynames (o); Get all property names//["P1", "P2"]
2. Get the information description of the attribute
var o = {p: ' a '}; Object.getownpropertydescriptor (o, ' P ')//Object {value: "A", Writable:true, Enumerable:true, Configurable:true}
3. Define a property
Object.defineproperty (Object, PropertyName, Attributesobject)
The first parameter is the target object, the second argument is the property name, and the third is the property description
Var o = object.defineproperty ({}, "P", { value: 123, writable : false, //can write enumerable: true, configurable: false }); o.p // 123 o.p = 246; o.p // 123 // because writable is false, So the value of this property cannot be changed
Define multiple properties
Var o = object.defineproperties ({}, { p1: { value: 123, enumerable: true }, p2: { value: "ABC ", enumerable: true }, p3: { //get: function () { return this.p1+this.p2 },              VALUE: THIS.P1+THIS.P2, Whether enumerable:true,//can be enumerated configurable:true //Property Description can be modified } }); o.p1 // 123 o.p2 // "abc" o.p3 // "123abc"
Note that get cannot be present at the same time as value or writable to describe unified properties
4. Check whether the property is enumerable
Object.prototype.propertyIsEnumerable () user.propertyisenumerable (' toString ');
5. Prohibit dynamic expansion of objects
Object.preventextensions (object);
var o = new Object (); Object.isextensible (o)//True Object.preventextensions (O); Object.isextensible (o)
6. Freeze the object so that it becomes a constant object (cannot extend properties and methods)
var o = {p: "Hello"}; Object.freeze (o); O.P = "World"; O.P//Hello o.t = "Hello"; O.T//undefined
Use of the JavaScript object class method