function within function 
Author Message
 function within function

Hi all,

does anyone have already experienced it :

i'd like to make function within function like

function ParentName()
    {
    function ChildName()
        {

        }
    ChildName();
    }
ParentName()

I checked it and it seem working fine

But, does anyone know if its possible to call ChildName() function outside
of the ParentName() function.

i d like to do it into a timeout purpose because :
function ParentName()
    {
    function ChildName()
        {
        setTimeout('ChildName()',20)
        }
    ChildName();
    }
ParentName()

It's not working because the browser can't retrieve ChildName...

Does anyone have any clue?

Thanx a lot

Laurent Goffin
http://www.*-*-*.com/



Mon, 21 Jul 2003 19:59:04 GMT  
 function within function
In order to make the internal function accessible to outside functions
you'll have to make it the property of some object. There are numerous
choices: you could make it a property of the String object, Array object,
Function object, the function that contains it, or any other Javascript
built-in object or existing object that allows you to assign new properties
to it.

function parentName()
{
      function String.childName()
      {
      }

Quote:
}

The inside function above has to be accessed as String.childName().

function parentName()
{
      function parentName.childName()
      {
      }

Quote:
}

The inside function above has to accessed as parentName.childName(). Note
that in order to access the inside function from outside code the outside
function has to called at least once. This is because the inside function
isn't set as an object property until the outside function is called.


: Hi all,
:
: does anyone have already experienced it :
:
: i'd like to make function within function like
:
: function ParentName()
:     {
:     function ChildName()
:         {
:
:         }
:     ChildName();
:     }
: ParentName()
:
: I checked it and it seem working fine
:
: But, does anyone know if its possible to call ChildName() function outside
: of the ParentName() function.
:
: i d like to do it into a timeout purpose because :
: function ParentName()
:     {
:     function ChildName()
:         {
:         setTimeout('ChildName()',20)
:         }
:     ChildName();
:     }
: ParentName()
:
: It's not working because the browser can't retrieve ChildName...
:
: Does anyone have any clue?
:
: Thanx a lot
:
: Laurent Goffin
: http://www.petrochemicals.atofina.com/
:
:
:



Mon, 21 Jul 2003 21:43:36 GMT  
 function within function
Quote:

> i'd like to make function within function like

    [example trimmed]

Quote:

> I checked it and it seem working fine

> But, does anyone know if its possible to call ChildName()
> function outside of the ParentName() function.

Could you be more specific about how you are using these functions? If
you're using the outer one as a constructor, then you can make the inner one
a method:

    function calcVolume() {
      return this.height*this.width*this.length
    }
    function box(l,w,h) {
      this.height = h
      this.width = w
      this.length = l
      this.volume = calcVolume
    }

    var b = new box(3,4,5)
    alert(b.volume)

But even if you're not doing this, I fail to see why your inner function
needs such limited scope. Why not just use it as a standalone?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.



Mon, 21 Jul 2003 22:03:24 GMT  
 function within function
Thnax a lot for ur answer,

of course, adding the function as a method of an object is matching a lot of
case,

but in this case i have :

function Name()
    {
    var a=1;
    }

i have local variable in the function and i was wanting to know how to call
both function with local variable in one and make it possible to use the
variable in both function without having to pass it as global variable or as
arguments of te function.

Thanx a lot for ur help

Laurent Goffin
http://www.porsche.be

Quote:
>     function calcVolume() {
>       return this.height*this.width*this.length
>     }
>     function box(l,w,h) {
>       this.height = h
>       this.width = w
>       this.length = l
>       this.volume = calcVolume
>     }

>     var b = new box(3,4,5)
>     alert(b.volume)

> But even if you're not doing this, I fail to see why your inner function
> needs such limited scope. Why not just use it as a standalone?

> --
> Dave Anderson



Tue, 22 Jul 2003 00:00:43 GMT  
 function within function

Quote:

> i have local variable in the function and i was wanting to know
> how to call both function with local variable in one and make it
> possible to use the variable in both function without having to
> pass it as global variable or as arguments of te function.

Don't just describe what you want -- show us your function. *THEN* we can
help you.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.



Tue, 22 Jul 2003 01:02:09 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Function within Function Syntax error

2. Reference function name within function

3. Scripted functions within Access SQL ??

4. Object Reference from within a function, Please help.

5. Using the Excel Trend Function from within VB

6. Calling functions within a script

7. Problem with IsDate function called within IIS/ ASP

8. Capture Function within IE

9. Can A function be done within a subroutine

10. Call API Function from within script

11. Running Access Functions from within ASP

12. access vbscript functions from within dynamic content

 

 
Powered by phpBB® Forum Software