tags:

views:

104

answers:

4

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: alt text

Thank you for your help....

A: 

Maybe I'm missing something, but can't you just set a "watch" to the global variables you're interested in?

Robusto
+1  A: 

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.

AlexV
Would you explain with a shor example?
uzay95
He wasn't asking if they were bad - wouldn't your post be a more appropriate comment seeing as you aren't actually attempting to answer the question?
Erik
Read his question. Quoting: "Is there any problem about global variables?". Anyway, added more info about my proposed solution and an example too!
AlexV
A: 

Wrong line is:

 arrResims = ArrResimler = sResimler

I can't set the values again after above line.

uzay95