What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Call a Function within a Function

Pages: (2): « First « 1 [ 2 ] Last »
Call a Function within a Function
Author: Message:
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: RE: Call a Function within a Function
quote:
Originally posted by markee
quote:
Originally posted by davidt
Yes, functions are global and so can be called from anywhere. It's only the variables withinn functions that stay within the function.
Though you can carry it over to another function when you call upon that second function, you just have to put it between the brackets.


When you're not talking about classes.
08-15-2006 09:42 AM
Profile E-Mail PM Find Quote Report
Intosia
Junior Member
**

Avatar
I'm dynamic ^^

Posts: 78
40 / Male / –
Joined: Mar 2004
RE: Call a Function within a Function
Like this:

code:
function test1(value) {
    Debug.Trace(value)
};

function test2() {
   test1('hi');
};



I gave the wrong link, here you can find all stuff like that:
http://en.wikipedia.org/wiki/JavaScript_syntax

This post was edited on 08-15-2006 at 09:49 AM by Intosia.
08-15-2006 09:46 AM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Call a Function within a Function
That's wrong?
08-15-2006 09:56 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Call a Function within a Function
quote:
Originally posted by davidt
Yes, functions are global and so can be called from anywhere. It's only the variables withinn functions that stay within the function.
functions can be perfectly local to another function too.

Just as variables can be global to all functions too. ;)

code:
var Globe1 = "Hello World"

function DoTheBanana() {
        var Localfruit = "Hello bananatown";
        Debug.Trace('Localfruit: ' + Localfruit);
}

function DoTheConga() {
        // Localfruit isn't valid in this function since it is declared locally inside DoTheBanana()
        // It's scope begins and ends in the function DoTheBanana()
        // Globe1 is valid in this function since it is declared globally.
        Debug.Trace('Globe1: ' + Globe1)
        var Localvar = "Hello bananatown";

        // Notice that we can declare a local variable to this function and that it will keep its value, even if have another local variable with the same name inside the DoTheBanana() function.
        var Localfruit = "I hate bananas";
        DoTheBanana();
        Debug.Trace('Localfruit: ' + Localfruit);
}

function NowForSomethingDifferent() {
        // Let's create a local function which is only valid inside NowForSomethingDifferent()
        function WoowLocalFunction() {
                Debug.Trace('This is a local function')
        }
        // And call it
        WoowLocalFunction();
}
Tip: try to not use global variables, unless it is absolutely nessecairly (goes for all languages you program in).

-------------------------------------------------------------------------

quote:
Originally posted by davidt
Does anybody know if Jscript is pass-by-value of pass-by-reference? I think it is the latter.
Numbers and Boolean values (true and false) are copied, passed, and compared by value. When you copy or pass by value, you allocate a space in computer memory and copy the value of the original into it. If you then change the original, the copy is not affected (and vice versa), because the two are separate entities.

Objects, arrays, and functions are copied, passed, and compared by reference.** When you copy or pass by reference, you essentially create a pointer to the original item, and use the pointer as if it were a copy. If you then change the original, you change both the original and the copy (and vice versa). There is really only one entity; the "copy" is not actually a copy, it's just another reference to the data.

When comparing by reference, the two variables must refer to exactly the same entity for the comparison to succeed. For example, two distinct Array objects will always compare as unequal, even if they contain the same elements. One of the variables must be a reference to the other one for the comparison to succeed. To check if two Arrays hold the same elements, compare the results of the toString() method.

strings are copied and passed by reference, but are compared by value. Note that if you have two String objects (created with new String("something")), they are compared by reference, but if one or both of the values is a string value, they are compared by value.


Note: When you pass a parameter to a function by value, you are making a separate copy of that parameter, a copy that exists only inside the function. Even though objects and arrays are passed by reference, if you directly overwrite them with a new value in the function, the new value is not reflected outside the function! Only changes to properties of objects, or elements of arrays, are visible outside the function.


**(To be very stricly correct that isn't entirly true though (JScript internally still makes a copy; but it also internally copies back the changed copy; aka: it isn't 'by reference' as in other languages <= hard to explain, though you shouldn't be bothered with it either, it's just per-info))

This post was edited on 08-15-2006 at 10:17 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-15-2006 10:01 AM
Profile PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On