constructor and prototype

Can someone explain this? 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; } My understanding here is: Foo.prototype is an Object whose constructor property is Function Foo. Foo.[[Prototype]] is 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] } Question 1: How did the look up using [[Prototype]] happen here. I would appreciate if someone can explain this to me. document.writeln(obj.constructor); // function Foo() { x =1; y=2; } .. no change document.writeln(obj.constructor.prototype); // function FooProto() { arrow = 1; bow = 2; } anotherObj = new Foo; document.writeln(anotherObj.constructor); // function Function() { [native code] } document.writeln(anotherObj.constructor.prototype); // function Empty() {} Question 2: Same question as Question 1. How did the Javascript interpreter perform the lookup?

以上就是constructor and prototype的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏