Jump to content

Search the Community

Showing results for tags 'closures'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 2 results

  1. Hello, I started learning JavaScript this week and I've been mostly using the JavaScript tutorial. It's been great, thanks a lot to all the authors! However, unless I'm mistaken and still don't fully understand, there is some information that I think is wrong or misleading about variable scopes. It prevented me from understanding closures until I worked through other people's code about main loops and did some testing. On the Function Closures page, it says: "Local variables have short lives. They are created when the function is invoked, and deleted when the function is finished." And on the Scope page, it says something similar: "Local variables are deleted when the function is completed." But a local variable is not deleted when the function is completed if there is a reference to it left somewhere outside the function. Of course, normally, there are no references to local variables left outside a function so the local variables are deleted upon exit. But when we declare a local subfunction that access a local variable and then give this subfunction to an outside object, so long as the outside object exist, the local variable of the original function will not be deleted either because it can still be accessed. I think this exception should be mentioned on both pages to help beginners (like me) understand how a local variable can still be accessed after the function is was declared in has been completed. I have some prior experience in C and VBA and I find the scopes of variables in JavaScript to be very different (probably due to not having a way of passing non-object variable references in function arguments). Or maybe I'm wrong, in which case I would be grateful if someone can explain it to me further. Thanks Terence
  2. Jim12345

    Closures

    Hello, I am looking over code plus the concept of closures. Below is the code: Closures are a powerful tool but can be tricky to understand. Mastering them, however, will allow you to write some very elegant code. Here’s an example: var saver = function (value) { return function () { return value; };};var retriever = saver(10);alert(retriever()); So the code alerts 10. If you rewrite the last line to be console.log(retriever); You get this: function () { return value; } I can watch the original code execute in Chrome Debugging Tools, but it doesn't help to understand it. Does anyone know I resource where I can watch say a table where the functions get created and variables get passed? Or can you create the table right here? Years ago a read a book about C and the author used tables to simulate memory locations for say functions, pointer to functions, variables and passing values by reference, etc. Thanks, Jim
×
×
  • Create New...