Le 9 sept. 2013 à 11:51, David Bruant <bruan...@gmail.com> a écrit :

> Le 09/09/2013 11:41, Claude Pache a écrit :
>> Le 9 sept. 2013 à 10:35, David Bruant <bruan...@gmail.com> a écrit :
>> 
>>> Le 08/09/2013 21:39, Brendan Eich a écrit :
>>>> In no case does anyone that I've spoken to, on TC39 or anywhere else 
>>>> around this planet, want *yet another* bottom type and singleton value a 
>>>> la null and undefined. No one. Those who speak Spanish and nearby 
>>>> languages tend to say "¡Basta!" -- I'm not kidding :-|.
>>> Two values are already arguably (!) a regrettable feature 
>>> https://github.com/DavidBruant/ECMAScript-regrets/issues/26
>>> 
>>> David
>> For me, it is a excellent feature, if we get the correct semantic:
> The issue has a lengthy debate too ;-)
> 
>> * `undefined` means "no value", or "nothing";
>> * `null` means "empty value", or (well) "null".
>> 
>> Practical usefulness:
>> * ES5: JSON stringification of object: `null` means `null`, and `undefined` 
>> means "no value, don't include the corresponding key".
>> * ES6: default values in function arguments (and maybe destructuring 
>> assignment?): `null` means `null`, and `undefined` means "no value, take the 
>> default".
> This is all after-the-fact justification. I understand the usefulness made of 
> this feature now that we have the 2 values, but I wonder if given the choice 
> to start over a newJS would be designed with 2 such values.

Even if the two particular cases I've mentioned were not forecasted when 
designing JavaScript, it does not diminish the value of the feature. When 
designing JS, some decisions had been taken, whose usefulness or badness has 
been understood only after experience.

> 
> Among the nonsense of undefined-as-a-value:
>    var wm = new WeakMap();
>    var o = {};
>    console.log(wm.has(o), wm.get(o)); // false, undefined
>    wm.set(o, undefined);
>    console.log(wm.has(o), wm.get(o)); // true, undefined
> 
> So we can "define" a weakmap entry with the "undefined" value. That's how 
> objects work, so that can't be changed. I wonder what has been gained for 
> weakmaps. For sure, some memory is wasted to keep the "has" boolean working.
> WeakMaps would feel simpler if wm.set(o, undefined) was an equivalent for 
> wm.delete... to me at least...
> 

Yes, `undefined` does have its quirks. Maybe, when designing JS some years ago, 
it would have been semantically better to make `obj.foo = _i_dont_exist_` an 
equivalent of `delete obj.foo`, so that getting `obj.foo` would search the 
value in the prototype chain of `obj` instead of returning `undefined`?

—Claude

> David



_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to