Harmony Proxy, Detect Whether Property Was Accessed Or Called
Is there a way using Proxy to detect if a property was executed, or was it just accessed? 'use strict'; require('harmony-reflect'); var Stub = { method: function (a) {
Solution 1:
Is there a way using Proxy to detect if a property was executed, or was it just accessed?
No, as JavaScript does not distinguish between attributes and methods. It's all just properties that are accessed, and their value can be called if it's a function.
You would need to return a function (so that it can be called) but also mimics a string, maybe by tampering with the .valueOf()
/.toString()
/@@toPrimitive
methods of that function object.
Solution 2:
I'm just a beginner with proxies, but as far as I know, the proxy cannot do what you need. It just gives you back the property you're looking for, it can't know how you're going to use it.
Post a Comment for "Harmony Proxy, Detect Whether Property Was Accessed Or Called"