Skip to content

Instantly share code, notes, and snippets.

@jrunning
Created April 24, 2011 04:16
Show Gist options
  • Save jrunning/939297 to your computer and use it in GitHub Desktop.
Save jrunning/939297 to your computer and use it in GitHub Desktop.
Getting a class property from an instance of a Backbone.js model (without naming the class explicitly)
var C = Backbone.Model.extend({
foo : function() { return this.constructor.bar; }
}, {
bar : 123
});
var ci = new C;
ci.foo();
// -> 123
var D = C.extend({}, { bar : 789 });
(new D).foo();
// -> 789
// Thanks @quackingduck! http://twitter.com/quackingduck/status/62003113367830528
// but...
var E = C.extend();
(new E).foo();
// -> undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment