var MethodProxy = function(object, queue) {
  this.init = function(object, queue) {
    this.object = object;

    for (var i = 0; i < queue.length; ++i) {
      this.forward(queue[i]);
    }
  };

  // payload : ['methodName', arguments*]
  this.push = this.forward = function(payload) {
    var methodName = payload.shift().split('.'),
        object     = this.object,
        method;
    while (methodName.length) {
      // dig into the object as many levels as needed (e.g. `FB.XFBML.parse`)
      if (method) {
        object = object[method];
      }
      method = methodName.shift();
    }
    return object[method].apply(object, payload);
  };

  this.init(object, queue);
};

var MethodProxy = function(object, queue) {
  this.init = function(object, queue) {
    this.object = object;

    for (var i = 0, len = queue.length; i < len; ++i) {
      this.forward(queue[i]);
    }
  };

  // payload : ['methodName', arguments*]
  this.push = this.forward = function(payload) {
    var methodName = payload.shift().split('.'),
        object     = this.object,
        method;
    while (methodName.length) {
      // dig into the object as many levels as needed (e.g. `FB.XFBML.parse`)
      if (method) {
        object = object[method];
      }
      method = methodName.shift();
    }
    return object[method].apply(object, payload);
  };

  this.init(object, queue);
};

Improve efficiency of queue loop
Improve efficiency of queue loop

This commit avoids a property lookup on every iteration of the
queue-consuming loop by first storing it in a variable, since we don't
expect the size of the array to change within the duration of the loop.
This will make the initialization slightly more efficient.

Change-Id: Ied891fd5fd360c9732e61c7cf8a645ec63801cc6
Reviewed-on: https://gerrit.causes.com/23783
Tested-by: Joe Lencioni <1dd72cf724deaab5db236f616560fc7067b734e1@causes.com>
Reviewed-by: Greg Hurrell <79e2475f81a6317276bf7cbb3958b20d289b78df@causes.com>
