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.

user3112634
  • 523
  • 4
  • 10
  • 26

2 Answers2

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
Amit Joki
  • 58,320
  • 7
  • 77
  • 95
  • 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 – user3112634 Dec 15 '14 at 14:17
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.

Nick Louloudakis
  • 5,856
  • 4
  • 41
  • 54