apply和call

两个都是在一个函数里面调用另一个函数

//相加函数
function add(a,b){
return a+b;
}
//在下面的函数里面调用上面的函数
function intro(){
var c=add.apply(this,[3,5]);
console.log(c);//8
var d=add.call(this,7,5);
console.log(d);//12
}
intro();
posted @ 2017-08-18 14:04  Ai-Long  阅读(156)  评论(0编辑  收藏  举报