Created
December 11, 2013 11:50
-
-
Save bastjan/7909074 to your computer and use it in GitHub Desktop.
spineextend include test
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
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