SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: JavaScript Nested Functions
-
Jan 30, 2007, 14:33 #1
JavaScript Nested Functions
I have this code:
Code:<head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <script language="javascript" > function outer(data) { var operand1 = data; function inner(operand2) { alert(operand1 + operand2) } } </script> <body> //<input type="button" value="1" onclick="outer(3)(2)" /> //<input type="button" value="2" onclick="outer(3)(2)" /> <div id="target"></div> </body> </html>
-
Jan 30, 2007, 15:12 #2
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
The inner function is called the same way as any other function but since it is defined locally to the outer function it can only be called from within outer and cannot be called from anywhere else since once outer finished the inner function will cease to exist.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 31, 2007, 05:26 #3
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
functions in javascript are values, "function foo() {...}" is just a shortcut form of "var foo = function() {...}"
Bookmarks