Last active
December 27, 2015 12:09
-
-
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.
This file contains 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
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 |
This file contains 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
Methodder = (method, scope) ->-> method.apply(scope, arguments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an interesting script, because I believe that you can simply just use
Function::bind(thisArg)
, such as indocument.body.addEventListener("click", console.log.bind(console));