Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: bindAll should throw a reference error if a given method is undefined #1692

Merged
merged 3 commits into from
Jun 21, 2014

Conversation

smarden1
Copy link
Contributor

If a given method is undefined, createCallback is going to return a function that will eventually throw an error when it is called. This is because createCallback returns a function that will evaluate to undefined.apply. If that's true, then it would be nice to catch these errors when we do the binding instead of when we call the unusable functions.

Here's an example...
https://gist.github.com/smarden1/b08f84fd3b1c363d403d

Additionally, I like getting the erroneous method name in my exception as bindAll can take a long list of functions and hunting down the erroneous one in that list is a bummer.

@jdalton
Copy link
Contributor

jdalton commented Jun 19, 2014

_.bindAll should use _.bind instead, that would take care of the error.

@smarden1
Copy link
Contributor Author

it's not currently using bind. That seems to have changed about 2 weeks ago with this commit by @megawac

b1f4dbd

Even still, it would be nice to get the name of the offending function as bind only gives you "Bind must be called on a function" and there can be many functions given to bindAll at once...

@jdalton
Copy link
Contributor

jdalton commented Jun 19, 2014

it's not currently using bind.

I'm aware of that. Adding extraneous error code is a slippery slope. We should leverage the error handling that exists without going overboard. Simply replacing createCallback with _.bind will take care of the primary issue.

@megawac
Copy link
Collaborator

megawac commented Jun 19, 2014

I definitely agree with reverting to using _.bind, missed that need when I was creating that patch. Its great to see the library and test suite evolving so quickly since the last version

…o ensure that errors are thrown for invalid input
@megawac
Copy link
Collaborator

megawac commented Jun 21, 2014

mitt

michaelficarra added a commit that referenced this pull request Jun 21, 2014
proposal: bindAll should throw a reference error if a given method is undefined
@michaelficarra michaelficarra merged commit 4fb271c into jashkenas:master Jun 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants