What is Object.create ()?
object.create (proto [, Propertiesobject]) is a new object creation method proposed in E5, the first parameter is the prototype to inherit, if not a child function, you can pass a null, the second parameter is the object's property descriptor, This parameter is optional.
For example:
function car (desc) {
THIS.DESC = desc;
This.color = "Red";
}
Car.prototype = {
getinfo:function () {return
' A ' + this.color + ' + This.desc + '. ';
}
};
Instantiate object using the constructor function
var car = object.create (car.prototype);
Car.color = "Blue";
Alert (Car.getinfo ());
The result is:A blue undefined.
1, the detailed explanation of the Propertiesobject parameter: (the default is False)
Data properties:
- Writable: Can write arbitrarily
- Configurable: Whether it can be deleted, whether it can be modified
- Enumerable: Can I enumerate with for
- Value: Values
Access properties:
- Get (): Access
- Set (): Setting
2, Example: see the example directly to know how to use.
The results are:
100
Yupeng
Yupeng1
201
I am Returning:yupeng
A Blue PORSCHE Boxter.
A Blue XXXXXXXX.
Aaaaaa
This is a new way of creating objects for JavaScript object.create (), I hope to help you learn.