On Sun, Jan 1, 2012 at 12:45 PM, Axel Rauschmayer <[email protected]> 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
> [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
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss