javascript 原型链

来源:互联网 发布:淘宝低价卖正货 编辑:程序博客网 时间:2024/05/18 15:55

其中,红色箭头表示真正的原型关系,在火狐或者chrome浏览器里面可以通过“__proto__”属性访问,但是,这个属性是用来理解原型链的,不建议在代码里面使用。

例如:

function a(){}var b=new a();//a相当于fn1所在位置,b相当于obj1所在位置console.log(a.constructor);//function Function() { [native code] }console.log(a.prototype);//a对象,包含constructor--function a(){}和__proto__--Object 两个属性console.log(b.__proto__);//a对象,同上,根据下面的判断可以得知console.log(b.__proto__===a.prototype);//trueconsole.log(b.constructor);//function a(){},通过b.__proto__找到constructor属性