Last active
December 21, 2015 03:58
-
-
Save frostney/6245794 to your computer and use it in GitHub Desktop.
Reusable mixins
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
do (root = @) -> | |
root.mixinList = {} | |
root.mixin = (target, name, params...) -> | |
root.mixin(target, n, params) for n in name if Array.isArray name | |
if typeof mixinList[name] is 'function' | |
mixinList[name].apply(target, params) | |
else | |
target[key] = value for key, value of mixinList[name] when not Object.hasOwnProperty.call target, key | |
null | |
root.mixin.define = (name, definition) -> | |
return unless name? or definition? | |
return if mixinList[name]? | |
mixinList[name] = definition | |
null | |
root.mixin.remove = (name) -> | |
delete mixinList[name] if name? and mixinList[name]? | |
null | |
root.mixin.exists = (name) -> Object.hasOwnProperty.call mixinList, name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment