Search code examples
javascriptfunctionundefined-function

Remove and re-add a function javascript?


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.


Solution

  • 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