JavaScriptstrict 模式總結

來源:互聯網
上載者:User

標籤:

由所示格式指令碼進入strict 模式

<script>    "use strict";    var a;</script>

 

strict 模式和正常模式的區別主要如下:

1、不支援八進位表示,如 var n = 023;

2、不支援with關鍵詞

3、無法刪除變數(只有configurable設定為true的對象屬性,才能被刪除)

1       "use strict";2   var x;3   delete x; // 語法錯誤4   var o = Object.create(null, {‘x‘: {5       value: 1,6       configurable: true7   }});8   delete o.x; // 刪除成功    

4、不能用“eval”或“arguments”做變數或函數參數名

5、新增保留字:implements, interface, let, package, private, protected, public, static, yield。

6、Declaring function in blocks  if(a<b){ function f(){} } 

7、不可重複定義函數屬性或定義重名函數

8、如果未使用new建構函式,函數中this不再指向全域對象,而是報錯。

function f(){    "use strict";    this.a = 1;  };  f();// undefined

  

 參考:MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode/Transitioning_to_strict_mode

   阮一峰 http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html

JavaScriptstrict 模式總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.