HighDots Forums  

simple variables as properties?

Javascript JavaScript language (comp.lang.javascript)


Discuss simple variables as properties? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: simple variables as properties? - 09-08-2008 , 11:58 AM






Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes:

Quote:
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.
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #22  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: simple variables as properties? - 09-08-2008 , 12:13 PM






Lasse Reichstein Nielsen wrote:
Quote:
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.
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.

Quote:
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).
Exactly.

Quote:
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.
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.

Quote:
There is no doubt what happens when you call a function. All we can
argue about is what to call it.
*g*


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16


Reply With Quote
  #23  
Old   
Jorge
 
Posts: n/a

Default Re: simple variables as properties? - 09-08-2008 , 12:50 PM



On Sep 8, 4:17*pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de>
wrote:
Quote:
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.
Nor the answer to the question. (?)

Quote:
However, the (strict) equals operation is pointless as we are dealing with a
host object here.
This has nothing to do with what we're talking about.

Quote:
(more verborrea)
idem.

Quote:
Could you show me how, when ?

(Not using 'with', .call() nor .apply())

You missed the point, again.
You duck and run away ?

Quote:
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
That's not an interpretation. It's all you need to 'learn' in order to
apply the rule.

Quote:
not what actually happens. *Which I am getting tired pointing out to you.
I'm always glad to learn when I'm wrong, so, having learned what you
need to in order to apply the rule, why don't you (instead of posting
much more -even unrelated- verborrea) just prove with an example where
else the rule fails (as Richard did wisely pointing out that it may
fail within a 'with', for those who use 'with') ?

Thanks,
--
Jorge.


Reply With Quote
  #24  
Old   
Jorge
 
Posts: n/a

Default Re: simple variables as properties? - 09-08-2008 , 12:59 PM



On Sep 8, 4:17 pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de>
wrote:
Quote:
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.
Nor the answer to the question. (?)

Quote:
However, the (strict) equals operation is pointless as we are dealing with a
host object here.
This has nothing to do with what we're talking about.

Quote:
(more verborrea)
idem.

Quote:
Could you show me how, when ?

(Not using 'with', .call() nor .apply())

You missed the point, again.
You duck and run away ?

Quote:
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
That's not an interpretation. It's all you need to 'learn' in order to
apply the rule.

Quote:
not what actually happens. Which I am getting tired pointing out to you.
I'm always glad to learn when I'm wrong, so, having learned what you
need to in order to apply the rule, why don't you (instead of posting
much more -even unrelated- verborrea) just prove with an example where
else the rule fails (as Richard did wisely pointing out that it may
fail within a 'with', for those who use 'with') ?

Thanks,
--
Jorge.


Reply With Quote
  #25  
Old   
Henry
 
Posts: n/a

Default Re: simple variables as properties? - 09-09-2008 , 10:14 AM



On Sep 8, 1:27 pm, Jorge wrote:
Quote:
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

Disregarding quibbling about whether - window - is equivalent to the
ECMAScript global object (and there is plenty of room for quibbling in
that direction), the specification allows another situation in which a
non-property accessor to the left of call operators may allow a - this
- that was not the global object. Host functions/object methods are
explicitly allowed to return a Reference type if they want to. In the
even that a host function did return a Reference type that had a non-
activation object as its - base - and its property name referred to a
function reference value, and the call operators were directly applied
to the value returned from the call then in that second function call
the - this - keyword would refer the - base - of the Reference type
(assuming it was no an Activation object).

I am not aware of a single host method/function that behaves in this
way, but that does not mean that they do not exist, and the
specification allows for the possibility of their existence.

The form of this construct (if it exists) would be:-

HostObject.methodName()();

- where the first set of parenthesise call the method and the second
set call the return value from the first function call, which is
allowed to be a Reference type for host functions/methods.

IE host objects support this form of usage. If, for example, you had a
number of forms each with a field named 'f' IE will happily execute:-

document.forms(0)('f');

- and the call to the return value from the - docuemnt.forms(0) -
knows which of the forms it is associated with, such that the
subsequent ('f') returns the reference to the field in the correct
form. This could be achieved by - docuemnt.forms(0) - returning a
Reference type, but in practice it is not (other manipulations of the
construct can be used to demonstrate that returning a Reference type
is not what is happening here).


Reply With Quote
  #26  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: simple variables as properties? - 09-10-2008 , 01:12 AM



Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de> writes:

Quote:
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]...
Quote:
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.

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #27  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: simple variables as properties? - 09-10-2008 , 02:21 AM



Lasse Reichstein Nielsen wrote:
Quote:
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.
First, that is *not* what Jorge was using to explain his meaning.

Second, you are pretty much preaching to the choir:

,-<48C54F28.1020106 (AT) PointedEars (DOT) de>
Quote:
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.

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.