In the expression bind(testArray.push, testArray) the name testArray still occurs twice. Can you design a function method, which allows you to bind an object to one of its methods without naming the object twice?

It is possible to give the name of the method as a string. This way, the method function can look up the correct function value for itself.
function method(object, name) {
  return function() {
    return object[name].apply(object, arguments);

var pushTest = method(testArray, "push");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: