Closed
Bug 1307168
Opened 9 years ago
Closed 9 years ago
Not able to get child objects methods in proxy object handler
Categories
(Invalid Bugs :: General, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: shimpiatul, Unassigned)
Details
(Whiteboard: [specification][type:bug])
What did you do?
================
I have javascript object such as var Countries = {};
I create proxy on this object to trap all method calls.
When i call a function like this Countries.Cities.getAll(),
i want to trap cities and getAll().
What happened?
==============
Trap is getting only Cities.
What should have happened?
==========================
Trap should get Cities.getAll()
Is there anything else we should know?
======================================
Comment 1•9 years ago
|
||
Can you provide a standalone testcase?
Component: API → Untriaged
Flags: needinfo?(shimpiatul)
Product: Mozilla Developer Network → Firefox
Reporter | ||
Comment 2•9 years ago
|
||
My code in app.js
var apiMall = function(){
};
obj = new Proxy({},
{ get : function(target, method, receiver)
{
console.log("type : " + target);
if(target[method] === undefined)
return function() {
//console.log('Method : ' + method + '(' + JSON.stringify(arguments) + ')');
};
else
return target[method];
},
});
included this file in html page using the script tag.
Then called the function obj.Cities.getAll() from one of the button handler.
On console its printing "type : " Cities when i clcked the button.
Actual its should print Cities.getAll().
I want to trap the object also.
Flags: needinfo?(shimpiatul)
Comment 3•9 years ago
|
||
In your code, object returned from get handler is not a Proxy.
If you want to trap get on the property, you need to return Proxy for the property access,
anyway, not a browser's bug.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → INVALID
Reporter | ||
Comment 4•9 years ago
|
||
Can u give me example.
It may not be a bug. But i want to achieve that functionality.
Basically what i want is that,if object.childObject1.childObject2.anyMethod() is called, i want to trap
childObject1, childObject1 and anyMethod. I want list of all the objects.
Comment 5•9 years ago
|
||
function f() {
return new Proxy(function(){}, {
get: function(target, name) {
console.log("get", name);
return f();
},
apply: function(target, thisArg, args) {
console.log("apply", args);
}
});
}
var object = f();
object.childObject1.childObject2.anyMethod(1, 2, 3);
Updated•9 years ago
|
Component: Untriaged → General
Product: Firefox → Invalid Bugs
Reporter | ||
Comment 6•9 years ago
|
||
Wow. Thanks I am almost closer.
Can u tell me how can i get childObject1, childObject2 and anyMethod() in one shot.
Means for every method call, i want to detect childObjec1, childObject2 and create a function.
You need to log in
before you can comment on or make changes to this bug.
Description
•