原型实例

function Fruits() {}
Fruits.prototype = {
color: 'red',
say: function(num1, num2) {
return 'i am ' + this.color + num1 + ' and ' + num2;
}
};
var apple = new Fruits();
alert(apple.say(1,2));
banana = {
color:'yellow'
};

alert(Fruits.prototype.say.call(banana, [1, 2]));
// alert(Fruits.prototype.say.apply(banana, [1, 2]));

会有出错,call的【1,2】被解析为字符串1,2放入num1,而num2为undefined;
posted @ 2017-02-16 21:40  shenq2014  阅读(121)  评论(0编辑  收藏  举报