Created
December 20, 2011 19:56
-
-
Save Raynos/1502989 to your computer and use it in GitHub Desktop.
klass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment