On 6/11/2014 5:40 PM, Alexandre Morgaut wrote:
On 11 juin 2014, at 17:11, André Bargull <[email protected]> wrote:
Quick note: that isConstructor isn't really viable unless you plan on using
it with constructors that do not have side effects.
Rick
The Proxy-based solution needs to be used in these cases. Now we just need to
wait until Proxies are available everywhere! ;-)
Not sure Proxy solve anything when we want to test the constructor nature of a
function and be sure invoking it won't change anything in the current
application context
To highlight what side-effects mentioned by Rick could be, a tested function
while invoked may:
- do DOM Manipulations,
- change properties in the global object,
- initiate Web Sockets or Web Workers...
Not safe at all...
From [1]:
```javascript
function IsConstructor(o) {
try {
new (new Proxy(o, {construct: () => ({})}));
return true;
} catch(e) {
return false;
}
}
```
This IsConstructor implementation does not trigger any side-effects and
works even when the underlying constructor requires arguments etc.
[1]
https://github.com/anba/es6draft/blob/master/src/test/scripts/suite/lib/assert.js#L53-L60
[...]
Alexandre Morgaut
Wakanda Community Manager
4D SAS
60, rue d'Alsace
92110 Clichy
France
Standard : +33 1 40 87 92 00
Email : [email protected]
Web : www.4D.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss