【发布时间】:2015-03-06 09:34:50
【问题描述】:
我的代码中有一个构造函数。我已经创建了该构造函数的实例。在新创建的实例中,我想通过使用原型方法来添加价值或功能。但是我在执行此操作时遇到错误。这是我的代码fiddle
function a(){
this.d=9
}
a.prototype.one=1;
a.prototype.two=2;
var j= new a();
j.prototype.three=3;
console.log(j)
【问题讨论】:
-
In newly created instance I want to add value or function by using prototype method.- 为什么? -
您混淆了 Function 对象的默认 prototype 属性和所有用于继承的对象的内部
[[Prototype]]引用其构造函数的 prototype。 -
@RobG:我认为你是对的
-
不幸的是,“原型”一词被通俗地用于两者。 ECMAScript 使用
[[Prototype]]作为内部属性,但是读写起来很别扭。除了“internal prototype of an instance”之外,一定有更好的名字。
标签: javascript