有人可以解释一下吗?
function Foo() {
this.x = 1;
this.y = 2;
}
function FooProto() {
this.arrow = 1;
this.bow = 1;
}
document.writeln(Foo.prototype); // [object Object]
document.writeln(Foo.prototype.constructor); // function Foo() { x =1; y=2; }
Run Code Online (Sandbox Code Playgroud)
我的理解是:Foo.prototype是一个Object,其构造函数属性是Function Foo.Foo.[[Prototype]]是Function.Prototype
obj = new Foo;
document.writeln(obj.constructor); // function Foo() { x =1; y=2; }
document.writeln(obj.constructor.prototype); // [object Object]
Foo.prototype = FooProto;
document.writeln(Foo.prototype); // function FooProto() { arrow = 1; bow = 2; }
document.writeln(Foo.prototype.constructor); // function Function() { [native code] }
Run Code Online (Sandbox Code Playgroud)
问题1:如何使用[[Prototype]]进行查找.如果有人能向我解释,我将不胜感激.
document.writeln(obj.constructor); // function …
Run Code Online (Sandbox Code Playgroud)