JavaScript知識點小記2

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.