Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.weisnix.org!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1642787.IUjFaCZJrE@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 13 Oct 2011 21:36:17 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: closure bindings Newsgroups: comp.lang.javascript References: <1094da0d-f929-49ec-9875-1096cb4ff481@db5g2000vbb.googlegroups.com> <6ff9c23e-a7d9-42fe-9e86-8799eddcfd93@6g2000prh.googlegroups.com> <2994749.SPkdTlGXAF@PointedEars.de> <1d5abff7-3bdd-4046-8c57-0d398f76049e@l11g2000prh.googlegroups.com> <8914731.SEqChMirdb@PointedEars.de> <09dd3324-8ad3-4af6-99f7-128c29c66711@j19g2000vbn.googlegroups.com> <1582342.FiOE1xPOLP@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 58 NNTP-Posting-Date: 13 Oct 2011 21:36:18 CEST NNTP-Posting-Host: d6fab8d7.newsspool2.arcor-online.net X-Trace: DXC=aiA@6FaQ_c_aoembcbF;DQA9EHlD;3YcR4Fo<]lROoRQ8kF Michael Haufe (TNO) wrote: >> Thomas 'PointedEars' Lahn wrote: >>> Michael Haufe (TNO) wrote: >>> > Thomas 'PointedEars' Lahn wrote: >>> >> BTW, how do you pass a *scope* to a method? >>> > - pass "this" from the global scope to get a reference to it >>> >>> `this' has nothing to do with scope. >> >> PowerShell has scope as an object to manipulate: >> $global:foo = "bar"; >> $local:foo="bar"; >> $7:foo="bar"; >> >> […] >> So for the above, the emulated effect can be seen for this specific >> case: >> >> var foo = "bar" >> >> function test(s){ >> WScript.Echo(s.foo) >> } >> >> test(this) //bar >> >> function change(s){ >> s.foo = "quux" >> } >> >> change(this) >> >> test(this) //quux > > And AISB, and we discussed at length before, `this' has nothing to do with > scope. You can see that confirmed, not refuted, here. It is only that > the ECMAScript Global Object serves as the Variable Object for the global > execution context (to avoid the even more complicated ES5 terminology) > that it *appears* *as* if* the opposite was the case. > > Wrap this in `(function() { … })()' and it will cease working (if it > worked before), i. e. both test() calls will show `undefined', and in > change() the global object will be added a `foo' property, if that. Err, the first test() call will show `undefined' (unless the global object already had a property of that name and a value different from `undefined'), the second one will show `quux' if creation or modification of the property of the global object was successful. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from (404-comp.)