![]() | |
![]() |
| | Thread Tools | Display Modes |
#21
| |||
| |||
|
|
Jorge wrote: 2.- 'this' is always preset to the global object *** except when/if the function is called as an object's method *** ? Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. |

#22
| ||||
| ||||
|
|
Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes: Jorge wrote: 2.- 'this' is always preset to the global object *** except when/if the function is called as an object's method *** ? Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. That's one view, but no more correct than the opposing one: that the "this" operator always evaluates to a value in a function code's execution context, even when the function is *not* called as a method. |
|
The closest the specification comes to defining "a method" is: "A function stored in a property of an object is called a method." (§ 4.3.3). |
|
In the example: function f(){return this;} alert(f()); the function "f" is never a method according to this definition, so it isn't called as a method. |
|
There is no doubt what happens when you call a function. All we can argue about is what to call it. ![]() |
#23
| ||||||
| ||||||
|
|
Jorge wrote: Thomas 'PointedEars' Lahn wrote: Nonsense. *What "Henry" pointed out instead was that without an identifier as base of the reference the scope chain matters, especially if there is no property accessor syntax at all. *The `with' statement is but an example of that I can't figure out another case in which a call to f() would preset 'this' to something !== window ? I do not know what you can figure out. |
|
However, the (strict) equals operation is pointless as we are dealing with a host object here. |
|
(more verborrea) |
|
Could you show me how, when ? (Not using 'with', .call() nor .apply()) You missed the point, again. |
|
2.- 'this' is always preset to the global object *** except when/if the function is called as an object's method *** ? Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. Let's say that f= object.method= function () { ... } Called as an object's method : object.method() Called as a function : f() However, that is merely your amateurish interpretation |
|
not what actually happens. *Which I am getting tired pointing out to you. |
#24
| ||||||
| ||||||
|
|
Jorge wrote: Thomas 'PointedEars' Lahn wrote: Nonsense. What "Henry" pointed out instead was that without an identifier as base of the reference the scope chain matters, especially if there is no property accessor syntax at all. The `with' statement is but an example of that I can't figure out another case in which a call to f() would preset 'this' to something !== window ? I do not know what you can figure out. |
|
However, the (strict) equals operation is pointless as we are dealing with a host object here. |
|
(more verborrea) |
|
Could you show me how, when ? (Not using 'with', .call() nor .apply()) You missed the point, again. |
|
2.- 'this' is always preset to the global object *** except when/if the function is called as an object's method *** ? Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. Let's say that f= object.method= function () { ... } Called as an object's method : object.method() Called as a function : f() However, that is merely your amateurish interpretation |
|
not what actually happens. Which I am getting tired pointing out to you. |
#25
| |||
| |||
|
|
On Sep 8, 1:04 pm, Thomas 'PointedEars' Lahn wrote: snip I can't figure out another case in which a call to f() would preset 'this' to something !== window ? Could you show me how, when ? (Not using 'with', .call() nor .apply()) snip |
#26
| |||
| |||
|
|
Lasse Reichstein Nielsen wrote: Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes: Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. |
|
You are mistaken. `f' is a property of the Variable Object of the execution context; an object inaccessible by code when it is function code, but an object nevertheless. That object is in the scope chain. |
#27
| |||
| |||
|
|
Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes: Lasse Reichstein Nielsen wrote: Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes: Incorrect, because a function is *always* called as an object's method, even though identifier resolution has to work along the scope chain, and may only find a property with that name as one of the Global *Object*. ...[example that didn't fly]... You are mistaken. `f' is a property of the Variable Object of the execution context; an object inaccessible by code when it is function code, but an object nevertheless. That object is in the scope chain. Ok, I accept that. But then: var x = (function(){ return this; })(); is calling a function that isn't a property of any object, i.e., isn't "called as a method" in any sense. |
|
Again, a function is always a method (there may be one exception: an ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ anonymous function immediately called after evaluation of its function ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ expression). Therefore, there is no case when it is not called as a ^^^^^^^^^^^ method. |
![]() |
| Thread Tools | |
| Display Modes | |
| |