Skip to content

Instantly share code, notes, and snippets.

@mako-taco
Created March 11, 2014 15:44
Show Gist options
  • Save mako-taco/9488478 to your computer and use it in GitHub Desktop.
Save mako-taco/9488478 to your computer and use it in GitHub Desktop.
Lessening our memory footprint
//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. */
}
@mcwhittemore
Copy link

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?

@mako-taco
Copy link
Author

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