What is 1.object.create ()?
Object.create (Proto [, Propertiesobject]) is a new way of creating objects in E5, the first parameter is the prototype to inherit, if not a child function, you can pass a null, the second argument 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 Functionvar car = object.create (car.prototype); car.color = "Blue"; alert ( Car.getinfo ());
The result is: A blue undefined.
Detailed explanation of 2.propertiesObject parameters: (False by default)
Data properties
- Writable: Is it possible to write any
- Configurable: Whether it can be deleted, whether it can be modified
- Enumerable: Can I enumerate with for in
- Value: Values
Access properties:
- Get (): Access
- Set (): Setting
3. Example: Just look at examples and know how to use them.
<! DOCTYPE html>The result is:
-Yupeng
yupeng1
201
I am Returning:yupeng
A Blue PORSCHE boxter.
A Blue XXXXXXXX.
aaaaaaReference article: 1.http://www.htmlgoodies.com/beyond/javascript/ object.create-the-new-way-to-create-objects-in-javascript.html2.http://www.jimmycuadra.com/posts/ ecmascript-5-object-creation-and-property-definition3.http://msdn.microsoft.com/zh-cn/library/ie/ff925952 (v= vs.94). aspxJavaScript a new way to create objects-object.create ()