函数中的this的指向
- 普通函数中的this是谁?-----window
- 对象.方法中的this是谁?----当前的实例对象
- 定时器方法中的this是谁?----window
- 构造函数中的this是谁?-----实例对象
- 原型对象方法中的this是谁?---实例对象
//严格模式:"use strict";//严格模式function f1() {console.log(this);//window }f1()
函数的不同调用方式
//普通函数function f1() {console.log("文能提笔控萝莉");}f1();//构造函数---通过new 来调用,创建对象function F1() {console.log("我是构造函数,我骄傲");}var f=new F1();//对象的方法function Person() {this.play=function () {console.log("玩代码");};}var per=new Person();per.play();