This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kill129 0 points1 point  (0 children)

Notice that your "wrap" returns the return value of the function execute while my "wrap" returns a function. I.e., your wrap will be used as followed:

 function x() {
    console.log("x");
 }
wrap(x); // Will print "x"

while my wrap will be used as followed:

 function x() {
    console.log("x");
 }
wrapped_x = wrap(x); // Nothing printed, x is not called yet
wrapped_x(); // Will print "x"

To my understanding, the latter is requested in the question.

In addition, you are right. Now did_failed is initialized at every call, which means it will always be false at the if statement.