Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created June 21, 2012 14:43
Show Gist options
  • Save ovaillancourt/2966121 to your computer and use it in GitHub Desktop.
Save ovaillancourt/2966121 to your computer and use it in GitHub Desktop.
//That's your constructor
var BaseObject = function(eventObj){
this._ev = $(eventObj || {});
}
//There it's the inheritance
BaseObject.prototype = Object.create(Object.prototype);
//Put your methods there
BaseObject.prototype.on = function(){
this._ev.on.apply(this._ev, arguments);
return this;
}
BaseObject.prototype.off = function(){
this._ev.off.apply(this._ev, arguments);
return this;
}
BaseObject.prototype.trigger = function(){
this._ev.trigger.apply(this._ev, arguments);
return this;
}
///////////////////////////////////////////////////////////////////////////////////
//Another constructor
var BaseView = function(tagName, attributes, content){
//Base class constructor call
BaseObject.call(
this,
domHelper.createElement(tagName || 'div', attributes, content)
);
}
//Inherit from BaseObject
BaseView.prototype = Object.create(BaseObject.prototype);
//Methods
BaseView.prototype.$ = function(selector){
return selector
? $(selector, this.el)
: $(this.el);
}
BaseView.prototype.render = function(){
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment