Asked By: Anonymous
For Example I have the following code
var myModel = Backbone.Model.extend({
foo: function(){
console.log('in foo..')
}
});
This foo
method works if I instantiate myModel
but is there any way to access it without instantiating ?
Solution
Answered By: Anonymous
You can pass it as the second argument to extend
:
var myModel = Backbone.Model.extend(
// instance properties
{
foo: function() {
console.log('in foo..')
}
},
// static
{
bar: function() {
console.log('in bar..')
}
}
);
Here, foo
will be available only in instances of myModel
, and bar
can be called statically. myModel.bar()
.