の存在に応じて、2 つのケースで驚くほど異なる動作をする非常に単純なアルゴリズムがあり"use strict"
ます。
ケース 1 :
func()
宣言が厳密モード内の場合、コンソール ログプリミティブよりも
"use strict";
// strict mode is on
Object.prototype.func = function() { return this; } // do nothing with the object
console.log( (4).func() ); // 4; primitive
ケース 2 :
func()
宣言が厳密モード外の場合、コンソールよりも同じ値のオブジェクトがログに記録されます
// strict mode is off
Object.prototype.func = function() { return this; } // do nothing with the object
"use strict";
console.log( (4).func() ); // Number {[[PrimitiveValue]]: 4}; object
そのような違いの源は何ですか?この変換の理由は何ですか?
厳密モードのさまざまな状態で、このような単純なアクションがどのように異なるのでしょうか?