this 谁调用就指向谁
例如:
var x = 5;//相当与window.x = 5
function test(){
alert(this.x);
}
test();//此时相当于window调用test方法
----------------------------------------------
//call aplly 说白了就是绑定函数的作用域
var color = 'red';
obj = {color:'yellow'}
function showColor(x,y,z){
alert(x+y+z);
alert(this.color)
}
showColor.call(window,1,2,3);//打印出 6然后red
showColor.call(obj,1,2,3);//打印出6然后yellow
---------------
apply跟call一样只不过传递的参数是数组
showColor.apply(obj,[2,3,4])//
--------------------------------
函数碰到return就返回 如果函数没有返回值 就返回undefined
--------------------------------
壁闭包的概念
function test(){
return function(){
alert('我是闭包函数');
}
};
var f = test();
f();调用函数
------------------------------------
转载于:https://blog.51cto.com/gggcgba/1273051