javascript - JS prototype原型问题
本文介绍了javascript - JS prototype原型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
var a = {
test : function () {
}
}
function b() { // b 构造函数
this.j=3;
}
var t = new b(); //T实例
b.prototype ; // b 的原型对象
b.__proto__; //?有没有这种写法
t.__proto__; //?有没有这种写法
t.prototype; //?有没有这种写法
a.prototype; //?有没有这种写法
a.__proto__; //?有没有这种写法
想问一下什么时候用prototype 然后b.__proto__; //?有没有这种写法
t.__proto__; //?有没有这种写法
t.prototype; //?有没有这种写法
a.prototype; //?有没有这种写法
a.__proto__; //?有没有这种写法
解决方案
初始状态只有函数有prototype.
实例的__proto__指向其构造函数的prototype.
函数也有__proto__因为函数是Function函数构造函数的实例。
这篇关于javascript - JS prototype原型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文