Closed Bug 1307168 Opened 8 years ago Closed 8 years ago

Not able to get child objects methods in proxy object handler

Categories

(Invalid Bugs :: General, defect)

All
Other
defect
Not set
normal

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?
======================================
Can you provide a standalone testcase?
Component: API → Untriaged
Flags: needinfo?(shimpiatul)
Product: Mozilla Developer Network → Firefox
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)
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: 8 years ago
Resolution: --- → INVALID
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.
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);
Component: Untriaged → General
Product: Firefox → Invalid Bugs
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.