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 ?
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With