Skip to content

Instantly share code, notes, and snippets.

@ukyo
Created September 20, 2012 17:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukyo/3757245 to your computer and use it in GitHub Desktop.
Save ukyo/3757245 to your computer and use it in GitHub Desktop.
Class.js
(function() {
var Class = function() {},
slice = Array.prototype.slice,
include;
Class.include = Class.prototype.include = include = function() {
var self = this;
slice.call(arguments).forEach(function(object) {
Object.getOwnPropertyNames(object).forEach(function(name) {
self[name] = object[name];
});
});
};
Class.extend = function(f) {
var parent = this.prototype,
proto = Object.create(parent),
cls = {},
ctor;
include.call(cls, this);
f.call(proto, parent, cls);
ctor = proto.hasOwnProperty('init') ?
proto.init :
function() { parent.constructor.apply(this, slice.call(arguments)); };
include.call(ctor, cls);
ctor.prototype = proto;
proto.constructor = ctor;
proto.init = void 0;
return ctor;
};
if(module && module.exports) {
module.exports = Class;
} else {
this.Class = Class;
}
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment