Skip to content

Instantly share code, notes, and snippets.

@frostney
Last active December 21, 2015 03:58
Show Gist options
  • Save frostney/6245794 to your computer and use it in GitHub Desktop.
Save frostney/6245794 to your computer and use it in GitHub Desktop.
Reusable mixins
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