Skip to content

Instantly share code, notes, and snippets.

@pellepim
Created December 2, 2011 08:52
Show Gist options
  • Save pellepim/1422399 to your computer and use it in GitHub Desktop.
Save pellepim/1422399 to your computer and use it in GitHub Desktop.
jsLint erroneous warning
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