by tlrobinson · 17y ago · 0 comments
js> var _
js> _ == undefined
true
Just doing "var _ = {}" should be sufficient.edit: however, this conflicts with Underscore.js (http://documentcloud.github.com/underscore/), but if you put an "if (typeof _ === "undefined")" around the assignment you should be ok
js> a = {}
[object Object]
js> b = {}
[object Object]
js> a == b
false
== only casts between certain primitive types, it doesn't do a deep comparison: js> x = null
null
js> y = undefined
js> x == y
true
js> x === y
false
Also undefined comparisons are still true with ===: js> var _
js> _ === undefined
true
But you're right, === should be the default choice, and only use == if you have a good reason.But libraries which expect to be able to use "_" for something other than gettext break this convention, and not only run the risk of screwing interoperability but also cause confusion for the (large number of) developers who are accustomed to "_" having a particular meaning.