I thought `typeof (class {}) === "function"` as well. And classes, to my
knowledge aren't callable.On Wed, Mar 2, 2016, 10:09 Mark S. Miller <[email protected]> wrote: > We maintain the invariant that the typeof of an object is stable -- it > never varies over time. An object is callable iff its typeof is 'function'. > By making the callability *and* the typeof of the proxy dependent on its > target, the two stay consistent. > > On Wed, Mar 2, 2016 at 6:51 AM, Олег Галабурда <[email protected]> wrote: > >> Yes, correct. I want to be able to make a callable Proxy for non-callable >> objects and don't understand why Proxies are having these restrictions. >> As you can see I, and any other developer, can easily bypass this >> restriction and make a wrapper function that actually will be never called >> and just redirect calls made on Proxy to a method of an object. >> > > Exactly. You are doing the right thing. This demonstrates that there is no > loss of intended generality from imposing this restriction. It imposes a > minor inconvenience for an uncommon case, as the price of being more > straightforward for common cases. > > > > >> If "apply" trap will be allowed for any type of targets this will make >> life easier :) >> >> 2016-03-02 16:19 GMT+02:00 Claude Pache <[email protected]>: >> >>> >>> Le 2 mars 2016 à 13:21, Олег Галабурда <[email protected]> a écrit : >>> >>> Hi! >>> >>> I'm currently working on project that allows to manipulate objects >>> passed from Worker. >>> https://github.com/burdiuz/js-worker-interface >>> >>> It creates wrapper objects that record actions applied to this object >>> and send commands to Worker. The problem is, when request is made I cannot >>> know what kind of object is this, so in case of function I should give >>> ability to make calls on the wrapper object. >>> As example, this code: >>> >>> var api = new WorkerInterface('../webworker.js'); >>> api.requestTime(); >>> >>> When "requestTime" was requested, it calls "get" and immediately returns >>> new Proxy to serve function call. But at time when Proxy is created I do >>> not know if that is function or not. Now I passed "apply" limitation by >>> adding wrapper function and make Proxy think it works with function. >>> >>> https://github.com/burdiuz/js-worker-interface/blob/master/source/interface/proxy.js >>> >>> >>> If I guess correctly your issue, you would like to have something >>> similar to: >>> >>> foo.bar // not-a-function >>> >>> and: >>> >>> foo.bar() // a method call >>> >>> ? Indeed, that is not possible in JavaScript (and that limitation is not >>> restricted to proxies). >>> >>> >>> I found in discussions why "call" trap was rejected, but didn't find >>> anything about restricting "apply" trap to functions only. >>> >>> >>> Probably because "X is a function" is, by design, strictly equivalent to >>> "X is callable"? >>> >>> —Claude >>> >>> >> >> >> -- >> Oleg Galaburda >> http://blog.actualwave.com/ >> http://jsinterface.googlecode.com/ >> http://guibuilder.org/ >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > > -- > Cheers, > --MarkM > _______________________________________________ > 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

