- var person ={
- name : "赵云",
- age:25,
- sayName:function(){
- this.sayHello();
- },
- sayHello:function(){
- console.log("person 中的 sayHello");
- }
- }
- function sayHello(){
- console.log(this);
- console.log("win 中的 sayHello");//
- (function sayName(){
- console.log(this.name); //
- }).call(this);// 调用 call, 改变指向 两次均指向 person
- }
- sayHello.call(person);
若单独执行立即执行函数, 均指向 Windows 对象
来源: http://www.bubuko.com/infodetail-3274637.html