Created
August 20, 2012 06:24
-
-
Save Breefield/3401553 to your computer and use it in GitHub Desktop.
Call/Apply
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
// You wrote this line | |
Function.prototype.call(current[ev], this, arguments); | |
// This line does what I want, calling the method on the current tool and passing the arguments. | |
current[ev].apply(this, arguments); | |
// Not sure what you were aiming for with the other line? |
Caveat that I ran into today: using call/apply on Function.prototype invokes it as expected, but returns undefined.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I meant to use apply. Invoking the function via Function.prototype helps guard against
Cannot call method 'apply' of undefined
errors if the object assigned tocurrent
doesn't have the event in question for whatever reason.