【问题标题】:Are listed in Where are specifications for 「constructor.prototype」列在“constructor.prototype”的规范中
【发布时间】:2015-04-24 00:00:24
【问题描述】:
function Js() {};
var js = new Js();
js.constructor.prototype; //Js {}
Js.prototype = {};
js.constructor.prototype; Object {}

function Js() {};
var js = new Js();
js.constructor;//function Js() {}
Js.prototype = {};
js.constructor;//function Js() {}

constructor.prototypeconstructor的区别?

在哪里已经描述了关于constructor.prototype的行为规范?

【问题讨论】:

  • js.constructor === Js,因此是js.constructor.prototype === Js.prototypeJs 是一个函数,Js.prototype 是一个对象。不确定你的问题到底是什么。如果您愿意,可以在spec 中阅读有关prototype 的信息。
  • 在哪里有描述?
  • 如果您要询问 prototype 的描述位置,请点击我评论中的链接。又来了:ecma-international.org/ecma-262/5.1/#sec-15.3.5.2
  • 回答谢谢。我想知道这个。

标签: javascript ecmascript-5


【解决方案1】:

constructor 对象仅引用生成该对象的函数,而prototype 包含将从对象继承的所有属性和方法,包括constructor 属性本身。

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2017-10-26
    • 2011-01-17
    • 1970-01-01
    • 2010-12-25
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多