knockoutjs replaced slow obj.__proto__ with Object.setPrototypeOf()

This commit is contained in:
djmaze 2020-10-28 20:19:38 +01:00
parent d49916731f
commit 5a0215987a
7 changed files with 100 additions and 157 deletions

View file

@ -7,10 +7,6 @@ ko.utils = (() => {
source && Object.entries(source).forEach(prop => target[prop[0]] = prop[1]);
return target;
},
setPrototypeOf = (obj, proto) => {
obj.__proto__ = proto;
return obj;
},
// For details on the pattern for changing node classes
// see: https://github.com/knockout/knockout/issues/1597
toggleDomNodeCssClass = (node, classNames, shouldHaveClass) => {
@ -22,8 +18,6 @@ ko.utils = (() => {
}
};
var canSetPrototype = ({ __proto__: [] } instanceof Array);
return {
arrayRemoveItem: (array, itemToRemove) => {
var index = array.indexOf(itemToRemove);
@ -35,14 +29,8 @@ ko.utils = (() => {
}
},
canSetPrototype: canSetPrototype,
extend: extend,
setPrototypeOf: setPrototypeOf,
setPrototypeOfOrExtend: canSetPrototype ? setPrototypeOf : extend,
objectForEach: objectForEach,
objectMap: (source, mapping, mappingOwner) => {