Skip to content

Instantly share code, notes, and snippets.

@oxUnd
Created March 19, 2014 00:28
Show Gist options
  • Save oxUnd/9633134 to your computer and use it in GitHub Desktop.
Save oxUnd/9633134 to your computer and use it in GitHub Desktop.
OO
var Class = function (base, extend) {
var parent = null;
if (Object.prototype.toString.apply(base) == '[object Function]') {
parent = base;
} else {
extend = base;
}
var fn = function () {
this.initialize.apply(this, arguments);
};
if (parent) {
var sub = function () {};
parent.prototype.$super_initialize = parent.prototype.initialize;
sub.prototype = parent.prototype;
fn.prototype = new sub();
}
for (var method in extend) {
if (extend.hasOwnProperty(method)) {
fn.prototype[method] = extend[method];
}
}
if (!fn.prototype.initialize) {
fn.prototype.initialize = function () {};
}
fn.prototype.constructor = fn;
return fn;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment