Question: For the following piece of code

```
a.b = function c(){
    return function e(){
        return this;
    };
};
d = a.b();

```

What will the value of d() be? This might not be a very good example, but I am just confused about what "this" will refer to.

Thanks,

Answer: 
From your code d is not the same as the "this". d will be a the function e, since you are setting d to be return value of the function call a.b() which returns a function, so

```
d = function e(){
    return this;
}

```

Now the value of `this` depends upon how you call this function d. `this` will be evaluated when this function is called. If you just call it like `d()` `this` will be the global `Window` Object.

and lets say if I have

```
obj ={foo:1, bar:2};

```

and I call like this

```
d.call( obj )

```

`this` will be the object obj. the call() method is used to call a function on any object, the passed object behaves as `this` inside that function.

I know Javascript this is really confusing and it isn't easy to get your head around it.
May be this can help <http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx>
`this` is a reference to the object on which method was called.
`d()` is similar `window.d()` (if there is no `with` instruction)