Skip to content

Instantly share code, notes, and snippets.

@watert
Last active August 29, 2015 14:06
Show Gist options
  • Save watert/1cbd997252ab7c3764ee to your computer and use it in GitHub Desktop.
Save watert/1cbd997252ab7c3764ee to your computer and use it in GitHub Desktop.
util.js / coffee without libs
View = do ->
extend = (obj,objs...)->
while o = objs.shift()
obj[k] = o[k] for k of o
return obj
class BaseView
constructor:(o={})->
@el = o.el
@$el = $(o.el)
@initialize?()
BaseView.extend = (props,statics)->
class NewClass extends @
extend NewClass.prototype,props
extend NewClass, statics
return NewClass
return BaseView
/* Extracts Logics from Backbonejs */
var View = (function($){
var View = function(options){
if(options.el){
var el = this.el = options.el;
if($){ this.$el = $(el); }
}
if(this.initialize)this.initialize.apply(this, arguments);
};
View.extend = function(protoProps) {
var parent = this;
var child;
child = function(){ return parent.apply(this, arguments); };
for(var k in protoProps){
child.prototype[k] = protoProps[k];
}
child.__super__ = parent.prototype;
return child;
};
return View;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment