[英]prototype property is absent in Chrome Dev Tools
我刚刚打开Chrome开发工具并输入以下代码:
function Car() {
this.value = 10;
}
var cc = new Car();
但是当我键入以下代码时:
cc.prototype
我undefined
。 为什么?
据我所知,“ cc”对象必须具有与Car构造函数相同的原型。
您需要使用cc.__proto__
来获取原型对象。
原型位于cc.__proto__
属性内。
浏览器(JS引擎)将其放置在此处。
新功能如下所示:
function new() {
var newObj = {},
fn = this,
args = arguments,
fnReturn;
// Setup the internal prototype reference
newObj.__proto__ = fn.prototype;
// Run the constructor with the passed arguments
fnReturn = fn.apply(newObj, args);
if (typeof fnReturn === 'object') {
return fnReturn;
}
return newObj;
}
此行是与您相关的行:
newObj.__proto__ = fn.prototype;
Car.prototype
是Car对象的所有方法和属性的定义。 cc
实例将其存储在__proto__
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.