Results 1 to 2 of 2

Thread: Scope and Nested Functions

Hybrid View

  1. #1
    Join Date
    Jan 2009

    Scope and Nested Functions

    I'm having trouble getting my head around one of those notorious Javascript foibles to do with scope. Scope and nested functions.
    Looking at the following plunk, I have two javascript objects, room1 and room2.

    Both have a nested function called nestedFunction inside a method called addPerson.
    In room1, that nested function is a lambda and the use of the this keyword blows away the global variable called 'person'.
    In room2, that nested function is a named function. The this keyword does not blow away the 'person' in the global scope.

    I think room1.nestedFunction is a function but not a method. But I'm not sure why. I guess because its context makes it a function expression as distinct from a function declaration.
    I not sure how that analysis would apply to room2.nestedFunction. Perhaps it is a method, but I'm not sure what method it is a function of. The addPerson object?

    So, I can basically see what is happening here. I just don't have an understanding of why. What is the difference between a lambda function and a named function when nested inside a property (addPerson). What is going on here?

    Thanks in advance.

  2. #2
    Join Date
    Sep 2008
    Jackson MS
    I looked at "script.js" in your link and line 33 has a warning which appears on mouseover.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles