I've got a function in jQuery, eg.
var asd;
function dosomething(){
for (i=0;i<=1000000;i++)
{
asd[i] = "(2^i)";
}
}
How can i unset the variables after the function?
delete $asd;
With this, i can clear the variable from the memory.
But can i reach the function's destructor in jQuery and how can I unset the whole function in the function's destructor?
THE WHY
The function and all the global variables are in the memory after running a script.
If i run something by the console, after the dom ready - since the all variables are still in the memory - the program will run.
So I'd like to clear the variables on the function's desctructor, then reset the function, or make it to null.
Because it will flush the whole script from the memory, so my page will be faster. Imagine a bit larger data structure than a single function, like 100 functions and 800 global variables. After the shown, i don't need the variables anymore.
Set it to undefined:
asd = undefined;
Update To unset a function, do:
myFunction = undefined;
You don't need the brackets. In your comment, you've misspelt undefined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With