Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created June 30, 2011 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/1055471 to your computer and use it in GitHub Desktop.
Save scottmessinger/1055471 to your computer and use it in GitHub Desktop.
Backbone's Extend Method
>Unit.show
function (){
console.log("show")
}
>Unit.show()
show
// the extend method--the second arg is the class properties.
var extend = function (protoProps, classProps) {
var child = inherits(this, protoProps, classProps);
child.extend = extend;
return child;
};
var Unit = Honeybee.Model.extend(
{
toJSON : function(){
var copy = ko.toJS(this)
return {title : copy.title}
}
,initialize: function(data){
_.extend( this, ko.mapping.fromJS( data, unitMappings, this ) ,
{
dirtyFlag : new ko.dirtyFlag(this, false)
}
)
}
}
,{
'show' : function(){
console.log("show")
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment