[whatwg] question about Web Storage setItem()'s behavior
白石俊平
shumpei.shiraishi at gmail.com
Wed Aug 12 01:28:35 PDT 2009
Thanks, Ian.
>> > --when value is null, should `setItem("key", null)` behave as like as
>> > `removeItem("key")`? (localStorage.setItem("key", null);
>> > alert(localStorage.length); <-- what is value displayed?)
>>
>> No, it's not the same as removeItem. It'll be set to 'null'.
>
> This changed recently; it'll now actually store the null value.
OK, I see.
and, when passed value is undefined (e.g. `setItem("key")`), which
behavior will be correct?
On current implementation of browsers, I looked as follows.
- IE and Firefox raise error, (arguments number is incorrect)
- Webkit family persist it as string ("undefined")
On Wed, Aug 12, 2009 at 4:10 PM, Ian Hickson<ian at hixie.ch> wrote:
> On Sun, 2 Aug 2009, Jeremy Orlow wrote:
>> On Sun, Aug 2, 2009 at 7:17 PM, 白石俊平 <shumpei.shiraishi at gmail.com> wrote:
>> >
>> > I'm implementing the HTML5 Web Storage using Gears
>> > (http://code.google.com/p/gear5/), so I have several questions with
>> > the spec.
>> >
>> > -Storage.setItem(key, val)
>> > --is key allowed non-string type object?
>>
>> Yes, but...
>>
>> --and when pass non-string object to key/value, is it automatically
>> > converted to string?(I'm considering to convert to use String
>> > constructor - String(key) )
>>
>> Yes.
>
> Correct.
>
>
>> > --when value is null, should `setItem("key", null)` behave as like as
>> > `removeItem("key")`? (localStorage.setItem("key", null);
>> > alert(localStorage.length); <-- what is value displayed?)
>>
>> No, it's not the same as removeItem. It'll be set to 'null'.
>
> This changed recently; it'll now actually store the null value.
>
> --
> Ian Hickson U+1047E )\._.,--....,'``. fL
> http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
> Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list