Created
June 10, 2014 10:10
-
-
Save zhusee2/9e7d23aadb206b006a1e to your computer and use it in GitHub Desktop.
Extend the idea from http://blog.yorkxin.org/posts/2014/06/10/mixin-and-concern-in-javascript
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
#=require underscore.js | |
class BaseClass | |
@concerning: (concernName, concernObj) -> | |
functionsToCopy = _.omit(mixin, "included", "classFunctions") | |
_.extend(this.prototype, functionsToCopy) | |
_.extend(this, concernObj.classFunctions) | |
if typeof concernObj.included is "function" | |
concernObj.included.call(concernObj, this) | |
Duck = | |
quake: -> "Quake!" | |
class Kamo extends BaseClass | |
@act: -> console.log "Acted" | |
@concerning "Sound", { | |
included: (base) -> | |
do base.act | |
quake: -> console.log "Quake!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment