function fruits(){} fruits.prototype = { color: "red", say: function(){ console.log("My color is " + this.color); } }; var another = { color: "yellow" }; var apple = new fruits; apple.say(); //My color is red apple.say.call(another); //My color is yellow apple.say.apply(another); //My color is yellow
区别:参数书写方式不同
call(thisObj, arg1, arg2, arg3, arg4);
apply(thisObj, [args]);
thisObj:call和apply第一个参数是一样的,该参数将替代Function类里面的this对象。
arg1,arg2....:是一个个的参数,
args:一个数组或类数组,是一个参数列表。