Alexandre.Morgaut at 4d.com
Wed Jun 11 08:40:26 PDT 2014
On 11 juin 2014, at 17:11, André Bargull <andre.bargull at udo.edu> wrote:
>> Quick note: that isConstructor isn't really viable unless you plan on using
>> it with constructors that do not have side effects.
> 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...
Testing the prototype is also one thing, but constructors can have no prototype properties or methods but only own properties defined at the instance level (potentially with getters / setters)
As created dynamically, such own properties are hard if not impossible to detect without executing the constructor
The only safe way I would see, for functions written in JS, would be to use a lexer on the source of the function provided by Function.prototype.toString.call(C)
But it would still not be 100% perfect and should probably throw an exception or return a error in some situations in which "this" manipulation may not be detectable.
ex: the function code evaluate a dynamic strings (that can not be parsed by a lexer) via eval(), setTimeout()/ setInterval(), or new Function()
Wakanda Community Manager
60, rue d'Alsace
Standard : +33 1 40 87 92 00
Email : Alexandre.Morgaut at 4d.com
Web : www.4D.com
More information about the es-discuss