开发者

In jQuery how delete variables and functions

开发者 https://www.devze.com 2023-03-25 12:57 出处:网络
I\'ve got a function in jQuery, eg. var asd; function dosomething(){ for (i=0;i<=1000000;i++) { asd[i] = \"(2^i)\";

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 ru开发者_如何转开发n 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


Remove the set of matched elements from the DOM. Use .remove( [selector] ).

Hope this will help You.

0

精彩评论

暂无评论...
验证码 换一张
取 消