標籤:ber undefined stl 代碼 上下文 asc efi 學習 函數
1 資料類型、判斷方法
基本類型:Undefined、Null、Boolean、Number、String
參考型別:Object
Ps:特殊物件類型:Array、Function、Math、Date、JSON、RegExp、Error
精確區分資料類型的方法:Object.prototype.toString.call()
console.log(Object.prototype.toString.call("34"));//[object String]console.log(Object.prototype.toString.call(66));//[object Number]console.log(Object.prototype.toString.call(function(){}));//[object Function]
2 執行內容
當前代碼的執行環境
3 this
this的指向是在函數被調用的時候確定的。
(1) 若一個函數中有this,但其沒有以對象的形式調用,而是以函數名的形式執行,則this指向全域對象。
function test(){ console.log(this); } test();//window
(2) 若一個函數中有this,且該函數是以對象方法的形式調用,則this指向的是調用該方法的對象。
var obj={ test:function(){ console.log(this); } } obj.test();//obj
(3) 若一個函數中有this,且包含該函數的對象也同時被另一個對象所包含,儘管這個函數是被最外層的對象所調用,this指向的也只是它的上一級對象。
var obj={ test:{ fun:function(){ console.log(this); } } } obj.test.fun();//test
(4) 若一個建構函式或類方法中有this,則其指向由該建構函式或類建立出來的執行個體對象。
class Test{ constructor(){ this.test = "test"; //類執行個體 } option(){ console.log(this); //類執行個體 } }
學習 & 感謝 & 推薦https://mp.weixin.qq.com/s/I7A1iC8Et6uOGZ234DsTlA
JavaScript知識點小記2