Skip to content

Instantly share code, notes, and snippets.

@bastjan
Created December 11, 2013 11:50
Show Gist options
  • Save bastjan/7909074 to your computer and use it in GitHub Desktop.
Save bastjan/7909074 to your computer and use it in GitHub Desktop.
spineextend include test
moduleKeywords = ['included', 'extended']
class Spine
class Spine.Module
@include: (obj) ->
throw new Error('include(obj) requires obj') unless obj
for key, value of obj when key not in moduleKeywords
@::[key] = value
obj.included?.apply(this)
this
@extend: (obj) ->
throw new Error('extend(obj) requires obj') unless obj
for key, value of obj when key not in moduleKeywords
@[key] = value
obj.extended?.apply(this)
this
Included =
included: -> console.log "included"
includedAttribute: ->
console.log "includedAttribute"
Extended =
extended: -> console.log "extended"
extendedAttribute: ->
console.log "extendedAttribute"
class Test extends Spine.Module
@extend Extended
@include Included
constructor: ->
console.log "Test constructor"
Test.extendedAttribute()
@includedAttribute()
test = new Test()
console.log "-----Keys of Test-----------------------------"
console.log key for key of Test
console.log "-----Keys of test-----------------------------"
console.log key for key of test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment