私はcompat tablesを見ていますが、IE 11 は (Miscellaneous の下で) この機能を除いてすべての ES5 をサポートしているようです: 提供された例にもかかわらず、それが何を意味するのか理解できません。
IE11 はほとんどの ES5 shim をサポートしているため、 ES5 shimの使用を避けることはできますか?
私はcompat tablesを見ていますが、IE 11 は (Miscellaneous の下で) この機能を除いてすべての ES5 をサポートしているようです: 提供された例にもかかわらず、それが何を意味するのか理解できません。
IE11 はほとんどの ES5 shim をサポートしているため、 ES5 shimの使用を避けることはできますか?
ここlength
で使用するプロパティは、実際にはFunction
コンストラクターのプロトタイプから取得Function.prototype.length
され、function
. リンクしたページでわかるように、プロパティは列挙できないためfor ... in
、特定のプロパティを列挙しないでください。次のスニペットは、プロパティが列挙可能ではないため、result
残り続けることを示していますtrue
。
var result = true;
for(var propertyName in Function) {
if(propertyName == 'length') {
result = false;
}
}
var isLengthEnumerable = Function.prototype.propertyIsEnumerable('length');
console.log('Function.prototype.length is enumerable: ' + isLengthEnumerable);
console.log('Result: ' + result);
上記のスニペットから、次の出力が得られます。
Function.prototype.length は列挙可能です: false
結果: true
しかし JavaScript では、すべてがオブジェクトでありObject.prototype
、 を含むプロトタイプ チェーンを通じてからプロパティを継承しますFunction
。length
では、同じプロパティをに割り当てるとどうなるObject.prototype
でしょうか?
var result1 = true;
var result2 = true;
Object.prototype.length = 42;
Object.prototype.otherProperty = 42;
for (var propertyName in Function) {
if (propertyName == 'length') {
result1 = false;
}
if (propertyName == 'otherProperty') {
result2 = false;
}
}
var isLengthEnumerable = Object.prototype.propertyIsEnumerable('length');
var isOtherPropertyEnumerable = Object.prototype.propertyIsEnumerable('otherProperty');
console.log('Object.prototype.length is enumerable: ' + isLengthEnumerable);
console.log('Object.prototype.otherProperty is enumerable: ' + isOtherPropertyEnumerable);
console.log('Result1: ' + result1);
console.log('Result2: ' + result2);
上記のスニペットから、次の結果が得られます。
Object.prototype.length は列挙可能です: true
Object.prototype.otherProperty は列挙可能です: true
Result1: true
Result2: false
Object.prototype.length
割り当てたばかりのプロパティは列挙可能であるため、これは になると予想されresult1
ますfalse
。ただし、Function
既にlength
プロパティを持っているため (ただし、列挙可能ではありません)、length
継承元のプロパティObject.prototype
は列挙されません。プロパティはシャドウされています。
これは IE11 では起こらないことです。Object.prototype.length
とにかく列挙され、同様result1
になるでしょう。false