Created
May 2, 2012 12:12
-
-
Save assertchris/2576151 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| has = (self, key) -> | |
| Object.hasOwnProperty.call(self, key) | |
| each = (object, method, context) -> | |
| for key in object | |
| if method.call(context, object[key], key, object) == false | |
| break | |
| object | |
| create = Object.create or (self) -> | |
| F = -> | |
| F.prototype = self | |
| new F | |
| mutator = (key, value) -> | |
| @prototype[key] = value | |
| @ | |
| implement = (obj) -> | |
| each(obj, (value, key) => | |
| if key != "constructor" and key != "inherits" and key != "mutator" | |
| @mutator(key, value) | |
| ) | |
| @ | |
| prime = (proto) -> | |
| superprime = proto.inherits | |
| if superprime | |
| superproto = superprime.prototype | |
| constructor = if has(proto, "constructor") then proto.constructor else | |
| if superprime then -> | |
| superproto.constructor.apply(this, arguments) | |
| else -> | |
| if superprime | |
| cproto = constructor.prototype = create(superproto) | |
| constructor.parent = superproto | |
| cproto.constructor = constructor | |
| constructor.mutator = proto.mutator or (superprime and superprime.mutator) or mutator | |
| constructor.implement = implement | |
| constructor.implement(proto) | |
| prime.each = each | |
| prime.has = has | |
| prime.create = create | |
| module.exports = prime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment