2

私はcompat tablesを見ていますが、IE 11 は (Miscellaneous の下で) この機能を除いてすべての ES5 をサポートしているようです: 提供された例にもかかわらず、それが何を意味するのか理解できません。

IE11 はほとんどの ES5 shim をサポートしているため、 ES5 shimの使用を避けることはできますか?

4

2 に答える 2

2

ここ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、 を含むプロトタイプ チェーンを通じてからプロパティを継承しますFunctionlengthでは、同じプロパティをに割り当てるとどうなる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

于 2018-06-14T21:22:51.890 に答える