ES6 doesn't need opt-in

Axel Rauschmayer axel at
Sun Jan 1 09:45:42 PST 2012

>    ({ 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"?


> I thought that 'window' is built-in so can either have a value or be 'undefined', but 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

    // undefined and null in several variations

    var myvar;
    console.log(exists myvar); // false

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

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

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list