Look at it like this:
(TL,DR: http://jsbin.com/axomev/edit ... yes, 'this' == 'window')
function fn09Wrapper() {
// same as before:
fn09();
// now ... do we have the same scope as fn09?
alert(this.op1+this.op2);
// and is that the same as window?
alert(window.op1+window.op2);
}
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="fn09Wrapper()">
</body>
</html>
On 28 July 2011 16:57, 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]
>
--
Pete Otaqui
[email protected]
+44 7949 945542
--
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]