Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <15678947.80IZ92ngzi@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 12 Mar 2014 11:06:24 +0100 User-Agent: KNode/4.11.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <0.4b944fce00eef4685de9.20140312030725GMT.874n34ktci.fsf@bsb.me.uk> MIME-Version: 1.0 Lines: 68 NNTP-Posting-Date: 12 Mar 2014 11:06:28 CET NNTP-Posting-Host: 62e2429b.newsspool1.arcor-online.net X-Trace: DXC=SDT4kYdcOL6i6K;>iZ]763ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@01CEWAg0_HN5DZm8W4\YJNb_T4YOS@=; X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:23565 Ben Bacarisse wrote: > ram@zedat.fu-berlin.de (Stefan Ram) writes: >> I start with the following code in a web page: >> >> document.writeln( 4 ); >> >> . It prints »4«. Ok. Next, I enclose the function expression >> in parentheses: >> >> ( document.writeln )( 4 ); >> >> Still prints »4«. Fine. But now, I try to get closer to what >> I actually wanted to write: >> >> ( true ? document.writeln : document.writeln )( 4 ); >> >> And this gives an error message here! Where are my >> first-class "functions as values", when I need them? > > document.writeln is a function but, being a method, it will refer to > properties in the document object (it does so using "this" of course). “Of course”? No. It is a method of a host object. All bets are off. > A simpler example: > > var wl = document.writeln; This could already be an error, referring to a host objects method not in a CallExpression. BTST. The host object referred to by “document” does not have to implement [[Get]] in the way of native objects. [1] > wl(4); // This is an error -- to what does 'this' refer in wl? We cannot know that, if there is such a value, and if it would be relevant. (Assuming native object-like behavior, “this” would either refer to the global object, or in strict mode would be the “undefined” value.) > You can get your first-class function back by binding the member > function to the object: > > var wl = document.writeln.bind(document); > wl(4); Unreliable at best: a host object’s method does not have to refer to a Function instance, it does not even have to have Function.prototype in its prototype chain which provides .bind() [2]. It just needs to be callable, i.e. implement [[Call]] (not: .call()) in a useful way. [3, 4] Certainly incompatible as Function.prototype.bind() was not introduced before ECMAScript Edition 5. [5] > Something similar will fix your conditional expression, too. You simply cannot know that. _________ [1] [2] [3] [4] [5] -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.