Issues of Array in JavaScript

It is noticed the initialization of a variable when declared as an element of array in not allowed. For instance:

var arr = [1, 2, 3];
var num = arr[0];

Assigning value to variable num "num = arr[0]; " needs to be done separately.

Since JavaScript arrays are assigned by reference, when array to be passed across iFrame, an issue of speed was met, especially for Mozilla Firefox.

Scripts in iFrame page:

var newArray = parent.arr;

When calling newArray[0] immediate after above declaration, it often generates error of "newArray is not defined". HTML pages are actual independent programs (stateless), it is no wonder reference across programs facing such kind of problem. It is therefore suggested avoiding passing array across parent page with iFrame page. Alternatively, slice array into single dimensional variable will do.

The reason behind this issue is this syntax of passing value is also true for object reference passing through HTML pages. We know that the reference acts as pointer to point to original variable rather than make a copy, any using of the reference is indeed reference back to parent HTML's object. It does cause a complex process behind the scent.

For same reason, if one wants to turn array in JavaScript, the best approach is to turn it into a string first, then pass the string to php, then use explode() to turn it back to array in php.


http://www.webdeveloper.com/forum/archive/index.php/t-93920.html

No comments:

Post a Comment

Labels