apply与call的区别
2019-11-11 本文已影响0人
近一亿
var xiaoming = {
name:'小明',
fruit:'橙子',
makeJuice:function( water, time ){
console.log( '正在榨:' + this.name + ' 家的' + this.fruit + '汁,加水:' + water + ' mL,用时:' + time + ' 分钟。');
}
}
var xiaohong = {
name:'小红',
fruit:'苹果'
}
xiaoming.makeJuice()
var arr = [500,10];
xiaoming.makeJuice.apply(xiaohong,arr) //apply参数是一个数组
xiaoming.makeJuice.call(xiaohong,500,10) //call可以传入多个参数