hasOwnProperty javascript メソッドで IE9+ および/または YUI 3 のバグを発見したと思います。ここにいる誰かが以前にこの問題を見たことがあるかどうか、または問題をさらに特定できるかどうか疑問に思っています。この問題について関係者に知らせたいのですが、IE チームと YUI のどちらに連絡する必要があるかわかりません。
詳細:
IE9/IE10の場合:
- 標準モードでのレンダリング
- 初期化された YUI 属性が含まれます (サンプル コードの 11 行目)。
hasOwnProperty は、有効な JavaScript 識別子ではないキーを含むオブジェクトに対して誤った値を返します (ab の b は問題ありませんが、a.5 の 5 は無効です)。有効な識別子にはこの問題はありません。
コード例:
http://jsfiddle.net/bobbyakadizzy/nLZJy/6/ (この問題は IE9/IE10 でのみ発生することに注意してください)
YUI.add("ie9-hasOwnProperty-test", function (Y) {
function IE9HasOwnPropertyTest(config) {
IE9HasOwnPropertyTest.superclass.constructor.apply(this, arguments);
}
Y.mix(IE9HasOwnPropertyTest, {
NAME : "IE9HasOwnPropertyTest",
ATTRS : {
attributeWithNumericProperty : {
value : {}
},
attributeWithStringProperty : {
value : {}
}
}
});
Y.extend(IE9HasOwnPropertyTest, Y.Base, {
initializer: function (config) {
// Uncomment this section below the problem will be "fixed". The problem appears to be related to attribute initialization.
// this.set("attributeWithNumericProperty", {});
var attributeWithNumericProperty = this.get("attributeWithNumericProperty");
attributeWithNumericProperty['1234'] = 999;
GLOBAL_attributeWithNumericProperty = attributeWithNumericProperty;
// If the object property is an identifier can be set after a dot (e.g. a.b) then the problem will not be hit
var attributeWithStringProperty = this.get("attributeWithStringProperty");
attributeWithStringProperty['a1234'] = 999;
GLOBAL_attributeWithStringProperty = attributeWithStringProperty;
}
});
Y.IE9HasOwnPropertyTest = IE9HasOwnPropertyTest;
}, "3.0.0", { requires : ["widget"]});
実行new Y.IE9HasOwnPropertyTest(); GLOBAL_attributeWithNumericProperty.hasOwnProperty('1234');
すると、true を返すべきときに false が返されます。