On Sun, Jan 1, 2012 at 9:09 AM, Axel Rauschmayer <[email protected]> wrote:

> > Maybe I am confused. Here is what I was imagining:
> >   var w = 1;  // w is declared and defined. typeof gives 'number'
> >   var x;  // x is declared, but is undefined. typeof gives 'undefined'
> >   y = 4; // y is not declared, is a global.    typeof gives 'number'
> >            // z is not declared                     typeof gives
> 'undefined.
> >
> > So how can I check to see that y and z are not declared?
> >
> > In:
> >   var b;
> >   if (typeof x !== 'undefined') b = x
> >
> > I don't get a ReferenceError. What I am I missing?
>
> Not a frequent use case (again, even less frequent with modules in ES6),
> but it exists: Boilerplate to Node.js-enable an asynchronous module
> definition.
>
>    ({ 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 window.foo can either have a value or be 'undefined', but
window.foo can not be declared.

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.)

jjb



> Alternative: wrap a function around define(), make define a parameter,
> perform the (same!) check when immediately-invoking the function.
>
> --
> Dr. Axel Rauschmayer
> [email protected]
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to