Prev: Quick question about newsreaders and post titles
Next: Using "new function() {...}" as a Singleton
From: Stone Zhong on 19 May 2010 00:48 Tired of reading, and make some fun :-) var a = function Foo() { return Foo; }(); alert(a); alert(a()); alert(a()()); alert(a()()()); all outputs are "function Foo() { return Foo; }"
From: Dmitry A. Soshnikov on 19 May 2010 02:01 On 19.05.2010 8:48, Stone Zhong wrote: > Tired of reading, and make some fun :-) > > var a = function Foo() { return Foo; }(); > > alert(a); > alert(a()); > alert(a()()); > alert(a()()()); > > all outputs are "function Foo() { return Foo; }" Ah, so you've "invented" "self-reproducing" (or "self-replicative") functions -- http://bit.ly/dacAAg ;) Dmitry.
From: Thomas 'PointedEars' Lahn on 19 May 2010 05:52 Stone Zhong wrote: > Tired of reading, and make some fun :-) > > var a = function Foo() { return Foo; }(); You want to avoid named function expressions. > alert(a); > alert(a()); > alert(a()()); > alert(a()()()); > > all outputs are "function Foo() { return Foo; }" The explanation why that is so, i.e. why passing a reference to a Function instance to the `alert' method of Window instances may result in displaying the code of the referred function is left as an exercise to the reader. PointedEars -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
|
Pages: 1 Prev: Quick question about newsreaders and post titles Next: Using "new function() {...}" as a Singleton |