Edwin Reynoso (2015-06-11T12:10:42.000Z)
eorroe at gmail.com (2015-06-11T12:15:40.877Z)
Ok so I got it work with the following code: ```JS function Person(fName, lName, age) { this.firstName = fName; this.lastName = lName; this.age = age; } Person.prototype = { logFullName() { console.log(this.firstName, this.lastName); }, getAge() { return this.age; } } var people = new Proxy([new Person('Edwin', 'Reynoso', 16), new Person('That', 'Guy', 1000)], { get(target, property) { if(target[property] !== undefined) return target[property]; var arr = []; for(var person of target) { if(person[property].constructor === Function) { return function(...args) { for(var person of target) { if(person[property]) arr.push(person[property](...args)); } return arr; } } else if(person[property]) { if(person[property]) arr.push(person[property]); } else { throw Error(property + ' is not defined'); } } return arr; } }); ``` However I still believe there should be an `invoke` trap in ES6 proxies. First here's what it would look like: ```JS var people = new Proxy([new Person('Edwin', 'Reynoso', 16), new Person('That', 'Guy', 1000)], { get(target, property) { if(target[property] !== undefined) return target[property]; var arr = []; for(var person of target) { if(person[property]) arr.push(person[property]); } return arr; }, invoke(target, functionName, arguments) { if(target[functionName]) target[functionName](...arguments); var arr = []; for(var person of target) { if(person[functionName]) arr.push(person[functionName](...args)); } return arr; } }); ``` Now isn't that much easier to read and write? Why have the `handler.get` trap do all the work. IMHO It's almost like saying only have one event listener for each type("click") for each element: ```JS document.body.onclick = function() { // handle first thing // handle second thing // handle third thing } ``` The above could get really complicated Over having the following: ```JS document.body.addEventListener('click', function() { // handle first thing }); document.body.addEventListener('click', function() { // handle second thing } document.body.addEventListener('click', function() { // handle third thing } ``` So why not do that for ES6 proxies as well by adding an `invoke` trap. If someone could give me a really good reason for why this is a bad idea, please do. I'm open minded.