函式中的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();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/157961.html
標籤:JavaScript
下一篇:JS面向物件
