Created
December 2, 2011 08:52
-
-
Save pellepim/1422399 to your computer and use it in GitHub Desktop.
jsLint erroneous warning
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
var PP = PP || {}; | |
PP.singleton = (function () { | |
var foo = function () { | |
// jsLint will warn that "bar" is not defined. Which is true in essence, but not in reality | |
// since the bar function is defined before it will be possible to call foo, it is not really an issue. | |
bar(); | |
}, | |
bar = function () { | |
alert("OMG"); | |
}; | |
return {foo: foo}; | |
}()); | |
// Solve this by refactoring to this, and the warning will go away: | |
PP.singleton = (function () { | |
var bar = function () { | |
alert("OMG"); | |
}, | |
foo = function () { | |
// jsLint will no longer warn, since bar has been defined above. | |
bar(); | |
}; | |
return {foo: foo}; | |
}()); | |
// If you find yourself unable to rearrage to get rid of this kind of warning | |
// It most likely means you have a too complicated structure and should refactor!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment