Created
March 11, 2014 15:44
-
-
Save mako-taco/9488478 to your computer and use it in GitHub Desktop.
Lessening our memory footprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//So we can totally use prototypes with knockout! Here's how... | |
var FloorElement = function () { | |
this.normalObservable = ko.observable("no optimization here"); | |
this.computedObservable = ko.computed(this.functionOnPrototype); | |
} | |
FloorElement.prototype.functionOnPrototype = function () { | |
/* this is very obvious in retrospect. Also lets us manually call some of these things, | |
which can be worthwhile. */ | |
} |
if we do it the current way
var FloorElement = function () {
this.normalObservable = ko.observable("no optimization here");
this.computedObservable = ko.computed(function () {/*...*/});
}
and make 100 floor elements, the anonymous function in the KO computed is actually created 100 times, as opposed to just pointing to a single function
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're memory wizard skillz are much better than mine. I'm guessing closures are higher footprint since the proto just looks up the chain?