0

I think extending the function is working correctly but I am not sure how to handle the parameters that are passed into the function, right now I get a x is undefined error.

Original function:

_adloadCallback = function(x, y) {
  //
}

Extended function:

(function() {
 _adLoadCallbackExtend =_adloadCallback();
 _adloadCallback = function() {
    console.log("Before");
   _adLoadCallbackExtend.apply(this, arguments);
    console.log("After");
  }
})();
1
  • 1
    Remove the () in _adLoadCallbackExtend =_adloadCallback();. You want to set the variable to the function, not call it. Also, you should probably add var there. Commented Dec 8, 2014 at 22:18

2 Answers 2

1

On line two, you are seting _adLoadCallbackExtend to being the result of calling _adloadCallback instead of setting it to _adloadcallback itself, which is what I think you are trying to do. Just get rid of the () at the end of the second line.

Sign up to request clarification or add additional context in comments.

Comments

1
_adLoadCallbackExtend =_adloadCallback();

should be

_adLoadCallbackExtend =_adloadCallback;

your way has _adLoadCallbackExtend be the result of calling _adloadCallback with no arguments instead of a "pointer" to the function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.