函數中的this的指向 普通函數中的this是誰? window 對象.方法中的this是誰? 當前的實例對象 定時器方法中的this是誰? window 構造函數中的this是誰? 實例對象 原型對象方法中的this是誰? 實例對象 //嚴格模式: "use strict";//嚴格模式 func ...
函數中的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();