I would recommend overriding the constructor of the parent class, instead creating a separate function proposed by Paul.
Thus, if you need a custom initialization function in child functions, the constructor saves the properties of the instance, and you do not need to worry about managing the scope or calling some global function passing in the context of this
, etc.
var Parent = Backbone.Model.extend({ constructor: function(options){ this.someProp = 'hello'; this.otherProp = 'world'; Backbone.Model.prototype.constructor.apply(this, arguments); } }); var child = Parent.extend({ initialize: function(){
This is the same idea as Pavel made in the second block of code, except that the constructor is separated from initialization in the trunk for this exact reason - so that you can redefine / configure the initialization actions without having to copy / paste redundant construction options every time, when you do it.
1nfiniti
source share