Skip to content

Instantly share code, notes, and snippets.

@colelawrence
Last active December 27, 2015 12:09
Show Gist options
  • Save colelawrence/7323526 to your computer and use it in GitHub Desktop.
Save colelawrence/7323526 to your computer and use it in GitHub Desktop.
Create functions, methods, with custom specified scopes to be called anywhere in your project.
Methodder = (method, scope) ->-> method.apply(scope, arguments)
onClickEvent=(event)->
# @log is a function of the scope
# @name is a property of the scope
@log @name, event
class FocusedObject
constructor:(@name)->
log: =>
console.log arguments
focus1 = new FocusedObject "Focus1"
# Using Methodder we set the scope to focus1
document.body.onclick = new Methodder onClickEvent, focus1
Methodder = (method, scope) ->-> method.apply(scope, arguments)
@colelawrence
Copy link
Author

This is an interesting script, because I believe that you can simply just use Function::bind(thisArg), such as in document.body.addEventListener("click", console.log.bind(console));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment