Le 31 déc. 2012 à 18:58, Axel Rauschmayer <[email protected]> a écrit :

>> Personally, I have issues with from- and to-String conversions when working 
>> with HTML form field values and data-* attributes. More precisely, I am 
>> careful to make these conversions manually, and I regret that JS doesn't 
>> warn me if I forget to do them. Indeed the following cases are problematic:
>> 
>> * String-to-Number : not triggered in, e.g.,  x + '1' when x is a Number.
> 
> I would assume the opposite being a problem: The user enters the number '33' 
> in a form field, you try to add 1, but forget that it is a string and end up 
> with '331' instead of 34.
It is what I meant: (but I should have written: x + myFormField.value to be 
clearer).

> 
>> * Boolean-to-String, Null-to-String: false and null are not converted to a 
>> falsy string.
> 
> When does this happen? Can you explain?

When you store «false» in a HTML data-* attribute, and retrieve it later from 
there, you don't get a falsy value if you had naively relied on the implicit 
conversions. Or, when you put a boolean in a hidden form field and expect it to 
be treated as truthy/falsy server-side by the program receiving the form.

—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to