Created
July 25, 2011 08:43
-
-
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/1103779 to your computer and use it in GitHub Desktop.
Classmethod
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
classmethod = (class_, methods) -> | |
for own name, method of methods | |
class_[name] = method | |
class_::[name] = (args...) -> | |
method.apply @constructor, args | |
class Atom | |
classmethod Atom, | |
property: (key) -> | |
@properties or= new Object | |
Object.defineProperty @properties, key, enumerable: true, value: 1 | |
class Human extends Atom | |
@property 'one' | |
@property 'two' | |
class Alien extends Atom | |
@property 'three' | |
@property 'four' | |
console.log Human.properties | |
console.log Alien.properties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment