gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

Correct value handler comparison (cast to string) #91

Closed STAH closed 10 years ago

gmac commented 10 years ago

I like the direction, but does that solve the problem that we set out to solve?

0 != '' + ''
// >> false
STAH commented 10 years ago

In our case $element.val() is always String, so your statement should be:

'0' != '' + ''
// >> true
STAH commented 10 years ago

After seeing jQuery docs/Google, val() can return String, Number or Array: http://stackoverflow.com/questions/9227268/how-can-val-return-number In this case we can use double cast:

0 + '' != '' + ''
// >> true
undefined + '' != '' + ''
// >> true
null + '' != '' + ''
// >> true
gmac commented 10 years ago

Great, thanks!