Common JavaScript Gotchas
jblotus.com
Common JavaScript Gotchas
1–10 of 28 posts
Re: Common JavaScript Gotchas
#2Re: Common JavaScript Gotchas
#3That's why developers should always lint their code. www.jslint.com
Re: Common JavaScript Gotchas
#4Re: Common JavaScript Gotchas
#5Re: Common JavaScript Gotchas
#6Great article, I will recommend it to every js beginner.
Re: Common JavaScript Gotchas
#7 var counter = (function () {
var i = 0;
return function () {
i += 1;
return i;
}
}());
Where the internal variable, i, is inaccessible to anything but the counter function itself.Re: Common JavaScript Gotchas
#8Using closures to encapsulate private variables is a good idea, but the way this article recommends doing it doesn't demonstrate any of the benefit as it doesn't really close over anything. I don't know if it's an example of good JS code, but something like the basic closure definition of a counter might have better demonstrated the ability to hide state: var counter = (function () { var i = 0; return function () { i…
Re: Common JavaScript Gotchas
#9That's why developers should always lint their code. www.jslint.com
Or http://www.jshint.com/ if they feel jslint is too harsh or arbitrary about some things.
Re: Common JavaScript Gotchas
#10Using closures to encapsulate private variables is a good idea, but the way this article recommends doing it doesn't demonstrate any of the benefit as it doesn't really close over anything. I don't know if it's an example of good JS code, but something like the basic closure definition of a counter might have better demonstrated the ability to hide state: var counter = (function () { var i = 0; return function () { i…
author here, it wasn't about hiding private variables. i was demonstrating using closures to avoid global namespace collisions which i think is generally a big problem for beginners.