Mark S. Miller (2013-07-16T23:41:37.000Z)
On Tue, Jul 16, 2013 at 4:10 PM, Erik Arvidsson <erik.arvidsson at gmail.com>wrote:

> All of the new constructors, Map, Set, WeakMap and WeakSet should fail
> when called as a function unless `this` already has a certain internal
> property, ie [[MapData]]. This is so that sub classing works as
> expected.
>
> However, all JS engines that supports Map, Set and WeakMap are future
> hostile and they all return a new instance when called as a function.
> For example, here is the V8 code:
>
> function MapConstructor() {
>   if (%_IsConstructCall()) {
>     %MapInitialize(this);
>   } else {
>     return new $Map();
>   }
> }
>
> I understand that fully supporting @@create requires a lot of work but
> until then we should at least throw when called as function to allow
> us to get out of this mess eventually.
>

I like the general idea. But when actually called simply as a function,
this would be unpleasant. Understanding that any ES5 behavior will be a
compromise to prepare the ground for ES6, I suggest this variant:

function MapConstructor() {
  if (%_IsConstructCall()) {
    %MapInitialize(this);
  } else if (this === void 0) {
    return new $Map();
  } else {
    throw ....;
  }
}

I already have a lot of code that simply calls WeakMap() without saying
"new". I suspect that others will too by the time they see v8's new
built-in WeakMaps.



> --
> erik
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130716/40f1c4b4/attachment-0001.html>
domenic at domenicdenicola.com (2013-07-18T16:31:21.357Z)
I like the general idea. But when actually called simply as a function,
this would be unpleasant. Understanding that any ES5 behavior will be a
compromise to prepare the ground for ES6, I suggest this variant:

```js
function MapConstructor() {
  if (%_IsConstructCall()) {
    %MapInitialize(this);
  } else if (this === void 0) {
    return new $Map();
  } else {
    throw ....;
  }
}
```

I already have a lot of code that simply calls WeakMap() without saying
"new". I suspect that others will too by the time they see v8's new
built-in WeakMaps.