public
Created

klass

  • Download Gist
klass.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// https://github.com/Raynos/pd
var pd = typeof window === "undefined" ? require("pd") : window.pd;
 
var klass = (function() {
// meta data name
var meta = pd.Name();
 
return klass;
 
function klass(parent, child) {
// if one argument set parent to Object
if (!child) {
child = parent;
parent = Object;
}
if (parent !== Object) {
// extract privates from meta data on parent
var privates = meta(parent).privates;
} else {
// if parent is object create new name
var privates = pd.Name();
}
// create new prototype object by inheriting from Parent
var proto = pd.extend(Object.create(parent.prototype), child(privates, parent.prototype));
// fix constructor <-> prototype link
proto.constructor.prototype = proto;
// get the constructor function
var constructor = proto.constructor;
// store the privates as meta data on this constructor
meta(constructor).privates = privates;
return constructor;
}
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.