1. ways to create objects:
//第一种方式:字面量
var o1 ={name:'o1'};
var o2=new Object({name:'o2'});
//第二种方式:通过构造函数
var M=function(name){this.name=name};
var o3=new M('o3')
//第三种方式:Object.create
var p={name:'p'}
var o4=Object.create(p)
M.prototype equal prototype object, by constructor associated prototype object constructor
_Proto_ instance of an object is equal to the constructor prototype
found by way of the prototype object prototype chain, method Prototype shared object is different instances
M.prototype.say=function(){
console.log('say hi')
}
var o5 =new M('o5')
M._proto_ constructor equal Function.prototype: M is the constructor Function, M can also be understood that normal functions Function instantiate the constructor.
Constructor and prototype _proto_ instance of an object is referenced by the same address
o3 is an example of the constructor is the prototype example of the constructor, the determination is not directly instantiated, use constractor
var new2=function(func){
var o=Object.create(func.prototype);
var k=func(o);
if(typeof k==='Object'){
return k
}else{
return o
}
}
o4 name attribute is come through the chain itself is a new prototype object p, so the object is empty o4