Reputation: 16642
I wanted to show problem with this video. Please watch...
I've 2 pages. Second page is sending selected pictures to the opener window(first one) using fResimleriEkle function.
I'm setting every element of array to another array variables (ArrResimler and ArrMetinler).
But when i fire the fAlbumOlustur function by clicking to button, i can't see the values of global variables.
Is there any problem about global variables?
The problem is in the picture:
Thank you for your help....
Upvotes: 2
Views: 630
Reputation: 16642
Wrong line is:
arrResims = ArrResimler = sResimler
I can't set the values again after above line.
Upvotes: 0
Reputation: 23108
Global variables are bad! Another one about how they are bad...
You could always pass the array in a "buffer" parameter in your functions which is cleaner IMO.
Example:
<script type="text/javascript">
function WorkWithArray(myArray, someOtherParam)
{
if (myArray.constructor.toString().indexOf("Array") == -1)
return false;
//Work with myArray here
myArray[myArray.length] = 'blah';
return true;
}
</script>
In JavaScript, we have functions and we have arguments that we pass into those functions. But how JavaScript handles what you’re passing in is not always clear. When you start getting into object-oriented development, you may find yourself perplexed over why you have access to values sometimes but not other times.
When passing in a primitive type variable like a string or a number, the value is passed in by value. This means that any changes to that variable while in the function are completely separate from anything that happens outside the function.
Passing in an object (an array is an object), however, passes it in by reference. In this case, any property of that object is accessible within the function.
See JavaScript: Passing by Value or by Reference for more info.
Upvotes: 1
Reputation: 31903
Maybe I'm missing something, but can't you just set a "watch" to the global variables you're interested in?
Upvotes: 0