Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 525c1e21-bd67-4735-ac99-b4b0e5262290/1103779 to your computer and use it in GitHub Desktop.
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/1103779 to your computer and use it in GitHub Desktop.
Classmethod
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