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

@ -59,14 +59,10 @@ ko.computed = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget, opt
computedObservable.hasWriteFunction = typeof writeFunction === "function";
// Inherit from 'subscribable'
if (!ko.utils.canSetPrototype) {
// 'subscribable' won't be on the prototype chain unless we put it there directly
ko.utils.extend(computedObservable, ko.subscribable['fn']);
}
ko.subscribable['fn'].init(computedObservable);
// Inherit from 'computed'
ko.utils.setPrototypeOfOrExtend(computedObservable, computedFn);
Object.setPrototypeOf(computedObservable, computedFn);
if (options['pure']) {
state.pure = true;
@ -485,9 +481,7 @@ var deferEvaluationOverrides = {
// Note that for browsers that don't support proto assignment, the
// inheritance chain is created manually in the ko.computed constructor
if (ko.utils.canSetPrototype) {
ko.utils.setPrototypeOf(computedFn, ko.subscribable['fn']);
}
Object.setPrototypeOf(computedFn, ko.subscribable['fn']);
// Set the proto values for ko.computed
var protoProp = ko.observable.protoProperty; // == "__ko_proto__"