New post today on Nettuts+ talking about the scope of "this". http://net.tutsplus.com/tutorials/javascript-ajax/fully-understanding-the-this-keyword/
Should be very relevant. On Thu, Jul 28, 2011 at 17:04, Xavier MONTILLET <[email protected]>wrote: > You use this whereas you didn't call the function as a constructor with the > new operator so it bind this to the global object aka window in browsers. > On Jul 28, 2011 11:58 AM, "Rahul" <[email protected]> wrote: > > function fn09(){ > > var op1 = 2; > > var op2 = 4; > > > > this.op1 = 7; > > this.op2 = 4; > > > > function compute1(){ > > return (op1+op2); > > } > > > > function compute2(){ > > return (this.op1+this.op2); > > } > > > > alert(compute1()); > > alert(compute2()); > > > > } > > > > > > <html> > > <head> > > <script type="text/javascript" src="chapter_Function.js" ></ > > script> > > </head> > > <body onload="fn09()"> > > > > </body> > > </html> > > > > > > the first alert gives 6 and second alert gives 11, > > > > so my question is when i do this.op1 and this.op2, wether op1 and op2 > > are propery added in "window" object ? > > > > > > -- > > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > > > To unsubscribe from this group, send email to > > [email protected] > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
