繁体   English   中英

Chrome Dev Tools中缺少原型属性

[英]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__来获取原型对象。

有关差异,请参见https://stackoverflow.com/a/9959753/4466618

原型位于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;

Object.prototype

Car.prototype是Car对象的所有方法和属性的定义。 cc实例将其存储在__proto__

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM