ES6 Proxy Function Call Trap

Claude Pache claude.pache at gmail.com
Tue Jun 9 07:39:13 UTC 2015


> Le 9 juin 2015 à 07:58, Edwin Reynoso <eorroe at gmail.com> a écrit :
> 
> 
> **Or does someone know how to do what I'm trying to accomplish**

Maybe the following code goes in the direction of what you want?

```js
var people = new Proxy([new Person('Edwin', 'Reynoso'), new Person('That', 'Guy')], {
	get(target, property) {
		if (target[property] !== undefined) 
			return target[property];
		var arr = [];
		for (var person of target) arr.push(person[property]);
		return new Proxy(arr, { 
			apply(target, thisArg, args) { 
				return target.map(item => Reflect.apply(item, thisArg, args)) 
			} 
		})
	}
});
```

About your proposal, I recall that, at some point in the history of ES6 draft, there was an `[[Invoke]]` MOP, and a corresponding `invoke` trap for proxies, that were finally eliminated.

—Claude
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150609/41cecbaa/attachment.html>


More information about the es-discuss mailing list