Цитата:
|
Цитата:
|
Короче тут обсуждали https://twitter.com/DmitryKorobkin/s...81153034596354
Если фиксить через new NOP, то возникает проблема: Object.create(null) instanceof Object → true, а так быть не должно, поэтому последний вариант:
//IE9-11 Object.create bug fix
(function () {
var object = Object.create({});
object[0] = null;
return object.hasOwnProperty(0); //→ false in IE9-11
}()) || new function () {
var create = Object.create;
Object.create = function (prototype, properties) {
//Object.defineProperties fixes a bug
if (properties) {
return create(prototype, properties);
}
//If Object.create works via new NOP, then
//Object.create(null) instanceof Object → true,
//but it's wrong.
//https://twitter.com/WebReflection/status/454342010288078848
if (prototype === null) {
return create(null, {
"": {
configurable: true,
writable: true
}
});
}
function NOP() {}
NOP.prototype = prototype;
return new NOP;
};
};
да, теперь для Object.create(null), метод Object.getOwnPropertyNames будет возвращать лишнее пустое свойство, но лучше варианта пока не придумал. |
А не проще тогда уж поправить hasOwnProperty
//IE9-11 Object.create bug fix
(function () {
var object = Object.create({});
object[0] = null;
return object.hasOwnProperty(0); //> false in IE9-11
}()) || new function () {
var hasOwnProperty = Object.prototype.hasOwnProperty;
Object.prototype.hasOwnProperty = function(prop) {
// если числовое свойство ищем
return +prop == prop ?
Object.getOwnPropertyNames(this).indexOf(""+prop) != -1 :
hasOwnProperty.apply(this, arguments);
};
};
|
Тогда и getOwnPropertyDescriptor, и propertyIsEnumerable фиксить придется, может еще что-нибудь
|
Баг интерфейса в FF28, замечен в винде:
Встроенный редактор JS иногда перестает исполнять код. Это бывает неочевидно, например, когда код чисто логический и не подразумевает каких-либо визуальных эффектов. Поэтому сопровождайте его хотя бы console.log, если ниче не логирует - лечится открыванием нового окна редактора. |
Дзен-трансгуманист, ты не сюда пости, а в баг-трекер мозиллы:)
|
Цитата:
|
Цитата:
//IE9-11 Object.create bug fix
(function () {
var object = Object.create({});
object[0] = null;
return object.hasOwnProperty(0); //> false in IE9-11
}()) || new function () {
var create = Object.create;
Object.create = function (prototype, properties) {
var isExecNum = properties && Object.getOwnPropertyNames(properties).indexOf("0") != -1;
if (!isExecNum) {
properties = properties || {};
/**
* Нужно добавить именно числовое свойство, иначе не будет работать
* например такой вариант не работает:
* var o = Object.create({}, {"": {configurable: true}});
* delete o[""];
* o[0] = null;
* o.hasOwnProperty(0) // -> false
* но если вместо пустой строки поставить число, то все работает хорошо
*/
properties["0"] = {
configurable: true
};
}
var object = create.call(this, prototype, properties);
if (!isExecNum) {
delete object["0"];
delete properties["0"];
}
return object;
};
};
|
О это хорошо, теперь фикс ничем не помешает.
//IE9-11 Object.create bug fix
(function () {
var object = Object.create({});
object[0] = null;
return object.hasOwnProperty(0); //→ false in IE9-11
}()) || new function () {
var create = Object.create;
Object.create = function (prototype, properties) {
var object;
if (properties) {
//Object.defineProperties fixes a bug
object = create(prototype, properties);
}
else {
//numeric key fixes a bug,
//it can be removed after,
//unlike alphabetic key
object = create(prototype, {
"0": {
configurable: true
}
});
delete object[0];
}
return object;
};
};
|
| Часовой пояс GMT +3, время: 20:16. |