If anyone wonders why every JavaScript framework under the sun rolls its own object system, and they're all incompatible, and almost nobody uses native JavaScript alone anymore, this is one of the reasons.
<i>It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like).</i><p>The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript.<p>I've commented before on people repeating this statement without ever examining it. I don't want to dredge up the arguments against it again ( <a href="http://news.ycombinator.com/item?id=1171202" rel="nofollow">http://news.ycombinator.com/item?id=1171202</a> ), mostly I just want to whine at it because it's so annoying. Why do you have to make JavaScript seem like something it's not? Are you trying to seem cooler by equating the language you work in to Scheme? What's wrong with JavaScript just being what it is?
<i>The var statement declares a variable as local to the current scope and the entire current scope, not just from the var statement onward. These local variables shadow any existing variables from outer scopes.</i><p>Err, I tested this on Chrome's Inspector console, and I don't see such behaviour. The article says <i>name</i> should be undefined at the time of the comparison in the below code, but it isn't (and I frankly can't see why anyone would want it to be). Is this a feature of my execution environment, or have I just completely misunderstood what the author means?<p><pre><code> (function(name){var cmp=name=="tim"; var name; return cmp})("tim") // returns true</code></pre>
Honestly, I think this is all too complicated. In Javascript, when you look at a line like this:<p><pre><code> a=1
</code></pre>
you have to guess in which scope it changes or creates the variable a. I prefer the way PHP is dealing with scope. You simply know that "a=1" is only affecting the current scope.
This kind of a bind is available in dojo via dojo.hitch and in google closure via goog.bind (make sure to require goog.base)<p>There's a $.hitch plugin in JQuery, it doesn't come with it by default.