这下面是我对整个 js 中对象的认识图 ,不知道队不对:
null;
function Object(){
this.prototype={
constructor:null,
};
this.__proto__=this.prototype;
};
function Function(){
this.prototype={
constructor:Object.prototype,
};
this.__proto__=this.prototype,
};
function Arry(){
this.prototype={
constructor:Function.prototype,
};
this.__proto__=this.prototype;
};
在此我还想请教下 js中 new的内部作用原理
虽然我英语很烂,不能完全看懂下面的描述,但是很明确的一点是: 对象的创建和原型的处理是在call之前的。
看过很多代码也不敢说是否是正确的
var p = new P()
这行代码大致的内部操作是:上面的第三步可能是没有的。因为函数的返回值在new操作符下是按下面进行处理的。
如果没有return语句,则返回上面的p。
如果有return语句,且return语句返回一个非null的object对象(包括数组,函数),则函数返回的不是this,而是这个object。
如果有return语句,且return返回的是非object对象,则函数返回p。