Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11993
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <1444259.yaknuLO9Tx@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Tue, 21 Feb 2012 13:44:33 +0100 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 8Bit |
| Subject | Re: "The this value" (Was: onclick=function(){obj.meth()}) |
| Newsgroups | comp.lang.javascript |
| References | <jp45k75qbcjbb5v8tavnmognds11hjihdh@4ax.com> <jhu992$b78$1@news.albasani.net> <1fb5k75j7mbjn04fm251o1omb0u1l1rbqv@4ax.com> <kff5k7dlo4jimo3d4bf6uple9okedrurq0@4ax.com> <jhuovr$95r$1@news.albasani.net> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 77 |
| NNTP-Posting-Date | 21 Feb 2012 13:44:40 CET |
| NNTP-Posting-Host | 1bf9a886.newsspool3.arcor-online.net |
| X-Trace | DXC=G3na1h[HY35T2Rfi6<W9f5McF=Q^Z^V384Fo<]lROoR18kF<OcfhCO;o;k`8g]<bO7DZm8W4\YJN<b@mF9jNikd5ob^NKRl8I480OdlVK:o:D8 |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:11993 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
Stefan Weiss wrote:
> On 2012-02-20 23:04, Gene Wirchenko wrote:
>> Advanced readers: "the this object" is awkward. "this" with or
>> without the quotes is confusing. Is there a better way to refer to
>> the this object in English text?
>
> It is awkward. I still haven't found a good way to reduce the
> awkwardness in plain text. It's easier when you can use markup (<code>)
> or italics or a different color, but on Usenet? *shrugs* I use what
> seems appropriate at the moment. Some use "this", or |this|, or `this'.
> I think that as long as it's clear what we're talking about, we're okay.
> It's not our fault that it has °this° silly name...
One must also differentiate between the "`this' value" (in the
specification) and the "value of `this'" (in program code).
> BTW, the specs always used to refer to it as "the this value", not "the
> this object".
Correct.
> IIRC, that's because in ES3 it is possible to set |this| to a type other
> than object.
I do not see how that could be possible. While it is true that you can
specify the `this' value as not being an object reference, the value of
`this' in ECMAScript Ed. 3-conforming program code will *always* be a
reference to an object [1].
> In ES5 (strict mode only?), |this| always has to be of type object.
Incorrect; rather the reverse is true.
In ECMAScript Edition 5 strict mode function calls or execution contexts,
`this' only refers to an object (and therefore could be said to be of
Type(…) "Object") if the function is called *explicitly* as the method or
constructor of an object [2]. IOW, in any String prototype method `bar',
for "foo".bar(), `this' is the primitive String value "foo", not a reference
to the String object referred by new String("foo") that needed to be created
to call the method in the first place. [This affects primarily the result
of the `typeof' operation, as if a primitive string value is used with a
property accessor, it is being converted internally to a String instance
anyway (so you still can use `this.trim()', but it is easier to tell string
values apart, or so perhaps was the intention of Ecma TC39.]
Further, with strict mode calls, the `this' value /is/ the `undefined' value
if the base value of the Reference of the call was `undefined' or `null'
[3]. IOW, in the strict mode call bar() or strict mode function context of
`bar' ("use strict" at the start of the function body), where `bar' is a
property of the Global Object and `globalRef' is a reference to the Global
Object, `this' will only refer to the Global Object if bar is called as
globalRef.bar(). While `bar()' being resolved to `globalRef.bar()' will
cause the `this' value /to be/ the `undefined' value.
Google V8 in Chromium 16.0.912.77 (Developer Build 118311 Linux) and V8 in
18.0.1025.33 beta (Linux) are (apparently; tested only in the Script Console
as yet) not conforming regarding the latter.
> I could be mistaken about the details, but I'm too lazy to look it up now
> (it's late, and the wine was good).
It would appear to be prudent if one, in good scientific tradition,
refrained from making claims that one is unable or unwilling to
substantiate.
PointedEars
___________
[1] ECMA-262 Edition 3 Final, section 10.2
[2] ECMA-262 5.1 Edition, sections 11.2.3, 13.2.1 and 10.4.3
[3] ibid.
--
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@news.demon.co.uk>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 14:02 -0500
Re: onclick=function(){obj.meth()} "Tom de Neef" <tdeneef@qolor.nl> - 2012-02-20 20:20 +0100
Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 20:39 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:34 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:13 +0100
Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:05 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:47 +0100
Re: onclick=function(){obj.meth()} John G Harris <john@nospam.demon.co.uk> - 2012-02-21 15:59 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 21:09 +0100
Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-20 20:29 +0000
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 16:50 -0500
Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-21 11:33 +0000
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 15:47 -0500
Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 22:38 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:12 -0500
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 14:04 -0800
"The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 01:37 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Gene Wirchenko <genew@ocis.net> - 2012-02-20 17:20 -0800
Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:44 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 22:31 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-22 10:55 +0100
Re: "The this value" (Was: onclick=function(){obj.meth()}) John G Harris <john@nospam.demon.co.uk> - 2012-02-22 15:58 +0000
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:30 +0000
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-20 13:43 -0800
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 23:17 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:48 -0500
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 00:57 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:03 +0000
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 19:05 -0800
Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:14 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:54 +0100
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 10:17 -0800
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:57 -0800
Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 13:39 -0800
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-22 05:07 -0800
Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:58 +0100
Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:45 +0000
Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:22 +0100
Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-21 08:12 -0500
Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:14 -0800
csiph-web