-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reverted the isFunction() and isDefined() refactor PR since you can't…
… pass undefined/undeclared vars to functions in JS
- Loading branch information
Showing
1 changed file
with
6 additions
and
14 deletions.
There are no files selected for viewing
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
f6eb3a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
erm... i think you can :-)
isFunction()
andisDefined()
would both return false - which is the purpose for thator am i missing something?
f6eb3a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pass an undeclared variable to a function in JavaScript it throws a
ReferenceError
.So your PR was throwing an error here:
Since
define
wasn't... defined ;}(for me at least, since I wasn't using require.js)
typeof
is an operator instead of a function, so we can use that to test if a var exists.For the rest of the calls... you are right, they would be fine since those vars are actually declared (though might not be defined). I think what I might end up doing is just making sure vars exist with some defaults that work without needing so many checks, like:
elements = elements || []
eachCallback = eachCallback || new Function()
f6eb3a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, right!
in this case i would go