1

How would I re-add a function so far I've done addSplatter = undefined; now this works perfectly for removing the function/breaking it so it doesn't do the function anymore but how would I re-add the function I've tried

addSplatter = addSplatter;

but that doesn't work any idea's on how to get the function "re-added" ? Thanks for reading.

1
  • it works perfectly, it just doesn't do what you want (since addSplatter is undefined at that pointer). Save the original function in a local variable instead. Commented Dec 15, 2014 at 14:08

2 Answers 2

4

Before making it undefined store the actual reference in a variable and use it to re-add it as a function.

var fnRef = addSplatter; // save function reference
addSplatter = undefined; // remove the function reference
addSplatter = fnRef; // make it a function again by assignment
Sign up to request clarification or add additional context in comments.

1 Comment

I see, so seen as iv set the function to undefined i'm atucally calling the function correctly but because its undefined its doing nothing, thanks. correct answer in 4 mins
0

What you are trying to do is to assign the variable value to the same variable.

This is syntactically and semantically correct in terms of the language but does not do what you want (it practically assigns the value stored in the variable (undefined) to itself). In order to do what you want, you need a second function referencing variable, as Amit Joki mentioned. This variable works as a "temporary storage" for the reference value of your function. You can then re-assign it to your old variable, as far as the temporary variable does not come out of scope and becomes destroyed, in a sense.

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.