Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1781123.YuqQMODZ1I@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 12 Mar 2014 03:52:18 +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+&. MIME-Version: 1.0 Lines: 73 NNTP-Posting-Date: 12 Mar 2014 03:52:22 CET NNTP-Posting-Host: 7193f1a8.newsspool1.arcor-online.net X-Trace: DXC=hBSnRFanIiPaAeROF2PWMQic==]BZ:af^4Fo<]lROoRQnkgeX?EC@@P9]aE[9kcEZ]DZm8W4\YJN\YUVHKH;GI^W<_e=dZX I start with the following code in a web page: There are no web pages. > document.writeln( 4 ); You have been told before not to use document.writeln(). Also, that code style is at least uncommon. You would be well-advised to stick to common code styles. > . It prints »4«. Ok. Next, I enclose the function expression > in parentheses: > > ( document.writeln )( 4 ); A function expression is something entirely different: function … (…) { … } You have enclosed a property access instead. > Still prints »4«. Fine. But now, I try to get closer to what > I actually wanted to write: > > ( true ? document.writeln : document.writeln )( 4 ); That is a pointless statement. > And this gives an error message here! “Gives an error message” is not a problem description. But I can guess what you get: “function called on incompatible object” or something like that. > Where are my first-class "functions as values", when I need them? You attempted to call the method as method of another object, here the global object, which is not allowed. The same is true for many other host object’s methods (short: host methods), and a common beginner’s problem/error. In general, if you want to use host methods in expressions, you need to wrap them in user-defined functions instead, so that the “this” value is preserved. Quick hack (script kids, don't try that at home): var myWrite = (function () { if (jsx.object.isHostMethod(document, "body", "appendChild")) { return function (s) { document.body.appendChild(document.createTextNode(s)); }; } return function (s) { /* CAVEAT: Not equivalent to the above */ document.write(s); }; }()); myWrite(42); I think the FAQ has an example written by someone else a long time ago. (It probably needs revision, but should give the general idea.) I strongly suggest you read the latest Edition of the ECMAScript Language Specification before further questions of that kind. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.