aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes problem in closures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem in closures" Watch "problem in closures" New topic
Author

problem in closures

Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Hi,
I am totally new to closures in javascript.I read a piece of code regarding closures but its not working.
The code is :


The output should be -> name:TEST
But I am getting -> name:undefined

The below code is not working either :



message in alert box is -> name:undefined

The above code works after the following changes :



message in alert box is -> name:TEST

Also when are closures created? Just by using inner functions or when we make inner functions accessible outside the scope of the function,containing the inner function.
Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

These all work fine for me, and should work fine for you: if they're not, be more specific with regards to how you're testing them.
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Thanks David,
I am sorry for the wrong code.The correct code is below.



Similarly the other code.

Thanks .
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And under what circumstances are you saying it doesn't work?
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
All I am saying is that it doesn't work if I am using the with statement.
Otherwise its working.
I am calling the test function on button click.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

I personally think that with is an abomination. Your mileage may vary.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Max White wrote:All I am saying is that it doesn't work if I am using the with statement.

Does for me, and don't know why it wouldn't unless your browser is broken or you don't have an element named formName, which I assume you do, otherwise you'd have noticed when you tried to debug it that you're getting a console message. But you didn't mention it when I asked you to be specific, so I assume your JavaScript matches up with your DOM.

And I agree--there's no good argument for using with.
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Hmmm...
Thanks for the help.Hope it works for me too
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in closures