2

「厳格を使用する」「これ」のルールを理解しようとしています。以下の場合に変更します。

( http://unschooled.org/2012/03/understanding-javascript-this/ )を読んだ後、関数 isStrictModeOn() は何にも「接続」されていないため、これは null を参照していると推測できます。これは、 this をグローバル オブジェクトにアタッチするだけの Javascript のより賢明な代替手段であると考えられます。この場合、「厳格な使用」が行っている変更の正しい解釈ですか?

http://www.novogeek.com/post/ECMAScript-5-Strict-mode-support-in-browsers-What-does-this-mean.aspx

function isStrictMode(){
    return !this;
} 
//returns false, since 'this' refers to global object and '!this' becomes false

function isStrictModeOn(){   
    "use strict";
    return !this;
} 
//returns true, since in strict mode, the keyword 'this' does not refer to global object, unlike traditional JS. So here,'this' is null and '!this' becomes true.
4

1 に答える 1