Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22469
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Wierd use of "new function() {}" |
| Date | 2013-12-29 02:26 -0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <l9o88p$rqd$1@speranza.aioe.org> (permalink) |
| References | <ROqdnRynNfBWDCLPnZ2dnUVZ5u2dnZ2d@giganews.com> |
On 29/12/2013 01:06, Robert Crandal wrote:
> Another question about John Resig's book, "Pro
> JavaScript Techniques" (C) 2006.
>
> On page 210, the following JavaScript code is
> seen:
>
> for (i = 0; i < elem.length; i++) new function() {
>
> /* code snipped here */
> }
>
> I don't think I've ever seen a "new function()" statement
> used right after a "for" statement. Is this valid code that
> is used for a certain purpose? Or am I looking at
> another possible typo in the book?
>
new function () { } is a "constructor anonymous function", that creates
a new Object {}.
Douglas Crockford once wrote: "It is never a good idea to put new
directly in front of function. For example, new function provides no
advantage in constructing new objects."
<http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/>
Coming from a John Resig's book, we can expect everything (the good, the
bad and ugly).
--
Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Wierd use of "new function() {}" "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-28 20:06 -0700
Re: Wierd use of "new function() {}" "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-28 20:42 -0700
Re: Wierd use of "new function() {}" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-29 17:45 +0100
Re: Wierd use of "new function() {}" Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-29 02:26 -0200
Re: Wierd use of "new function() {}" John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-29 11:07 +0000
Re: Wierd use of "new function() {}" Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-29 11:52 -0200
Re: Wierd use of "new function() {}" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-29 19:39 +0000
Re: Wierd use of "new function() {}" John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-30 15:27 +0000
csiph-web