ES6 doesn't need opt-in

Rick Waldron waldron.rick at gmail.com
Sun Jan 1 10:31:20 PST 2012


On Sun, Jan 1, 2012 at 12:45 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

>     ({ define: typeof define === "function"
>>        ? define  // browser
>>        : function(F) { F(require,exports,module) } }).  // Node.js
>>    define(function (require, exports, module) {
>>        // Node.js module code goes here
>>    });
>>
>
> Ok, thanks for the example. Here the test
>   typeof define === 'function'
> is equivalent to
>   typeof window.define === 'function'
> Is this testing whether 'define' is "declared"?
>
>
> Yes.
>
> I thought that 'window' is built-in so window.foo can either have a value
> or be 'undefined', but window.foo can not be declared.
>
>
> Note: `window` does not exist on Node.js (and possibly other non-browser
> environments).
>
> Anyway, if this example illustrates your use case, then it is the
> important case in my opinion (dynamic function overloading, supporting
> multiple callers). (And I don't see how any dedicated operator can help.)
>
>
> If there was an operator `exists`, the following two expressions would be
> equivalent. I prefer the latter expression, because it is more explicit.
>
>      typeof define === "function"
>      exists define && define instanceof Function
>
> The exists operator would work as follows (slightly edited from a previous
> email):
>
>     console.log(exists globalUnknown); // false
>

Same as...
  ( "globalUnknown" in this )      // anywhere
  ( "globalUnknown" in window ) // browser
  ( "globalUnknown" in global )   // node
  ( "globalUnknown" in self )      // workerglobalscope

But this is _so_ common that it might warrant an upgrade


>
>     // undefined and null in several variations
>
>     var myvar;
>     console.log(exists myvar); // false
>

"exists" is misleading here, "myvar" does exist - you just initialized it,
but did not assign a value. If  I've understood 12.2 correctly, "myvar"
definitely "exists"


>
>     console.log(exists undefined); // false
>
    console.log(exists null); // false
>

Same argument as given for "myvar"


>
>     var obj = {};
>     console.log(exists obj.prop); // false
>

This makes complete sense, but still same as my first example

  ( "prop" in obj )



Rick





>        --
> Dr. Axel Rauschmayer
> axel at rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120101/9fb6a7d1/attachment.html>


More information about the es-discuss mailing list