> ({ 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
// 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
[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