首页 新闻 赞助 找找看

Javascript代码的小小疑问(19)

0
[已解决问题] 解决于 2015-06-10 14:24

function Shape() { 

this.x = 0;

this.y = 0;

}

 

Shape.prototype.move = function(x, y) { 

this.x += x;

this.y += y;

console.log("This is moving action...");

}

 

function Rectangle() { 

Shape.call(this, arguments);

Rectangle.prototype = Object.create(Shape.prototype);

}

var rect = new Rectangle();
alert(rect instanceof Rectangle);  //fasle? 某些教程上说是true
alert(rect instanceof Shape);      //false? 某些教程上说是true
rect.move(2, 3);                      //没定义?

Coca-code的主页 Coca-code | 初学一级 | 园豆:10
提问于:2015-06-10 13:55
< >
分享
最佳答案
0

Rectangle.prototype = Object.create(Shape.prototype);  移到构造函数以外

Coca-code | 初学一级 |园豆:10 | 2015-06-10 14:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册