This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Trying to invoke function using keyword 'this' , but can't retrive the value in the function

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi this is the code which i wrote



This is the above code, now the problem is if i put alert showing obj.aValue, the value it 'undifined', why its not picking the value even when i passed 'this' as a parameter.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul,
I guess the problem here is the "this" does not refer to the var objMain, but refer to the global window object. Therefore, the obj.aValue and obj.bValue are undefined.

Here is the usage of this you may need to know:

when a function is invoked as a function rather than a method of a object, the "this" refers to the global window object.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic