Does javascript still allocate memory for the "IF" scenario if the condition evaluates to false? -


So many people ...

I have an IF statement that is now 99.7% accurate , Which has a check, to see if the browser is DOM 1+ enabled, and then loads a large block of code.

Therefore it is logical to put "if (true)", and leaving it is the "other" part, but I wonder if the old browser will still continue to parse the code and allocate memory First, before deciding to break execution ....

It is not that I will take care of this point, because we <10 p>

I think my question More or less: The browser pauses the entire file

b> and First, allocate memory before executing the conditional statement, which is the first thing before anything else?

Thank you in advance :)

Two things have been implicated from the execution context And these are an effect, even if the code in question never arrives: function and var .

As soon as the block is entered a var , that code block will have "reserved memory" for that variable, but that variable's value is only undefined will be an indicator for the object, so it is only a small number of bytes. function

Evaluate both "reserved memory" and function for variables by entering the function statement in a code block, resulting in Before the first line of code in the block is executed, the function according to the variable according to the variable. Similarly you can call a function which is defined only below the script.

Under the ECMAScript standard rules, you can only enter the function statement in the root of the code block; It is to say that:

  if (true) {function f () {...}}  

is illegal though, the browser is still mango And actually, when you separate it between browsers, avoid this (avoid the named inline function expressions, which are incorrectly uplifted in IE's JScript and are subject to double evaluation.) < / P>

If you really want to assign any memory to frequencies These are the tasks that you do not intend to use, put them into their own function blocks, it is a common strategy to maintain a clean nomenclature in the library code. Example:

  if (condition) (function () {var foo = 1; function bar () {alert (foo);}}) ();  

The amount of memory you can avoid doing so is very low.

But every major browser today is DOM Level 1 enabled; If you have backup codes to support Netscape 4 in your scripts, then it's time for the last time to delete it. Now the basic desktop browser IE 6 is.

IEMobile in earlier versions of IOMobile 8 / WinMobile 6.1.4 is still a common browser for which simple DOM manipulations are still a problem. However, this browser is so bad that almost no script is not as bad Will be as much; Everything is necessary for a lot of things.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -