Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Defining functions in JavaScript Date: Mon, 07 Apr 2014 19:26:30 +0200 Organization: PointedEars Software (PES) Lines: 94 Message-ID: <5691463.I9jde9eDty@PointedEars.de> References: <1d82e037-4811-4a45-9668-985bdac67e45@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1396891591 26005 eJwFwQEBwDAIAzBLwGlhdtiofwlP8NF5KwkmBC1e16XRnmhXMLrFkbPHoYnBamOrWydyfhhREQ4= (7 Apr 2014 17:26:31 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 7 Apr 2014 17:26:31 +0000 (UTC) User-Agent: KNode/4.11.5 X-User-ID: eJwNy8kBwCAIBMCWBFyOclYD/ZcQn/MYmIvf2A7fGExcMWUktMSLGmB3hJX2rl5Cmz6N4pN+llqrJ+dYvC7kDzjhFUc= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. AbdulFattah Popoola schrieb: >> http://abdulapopoola.com/2014/04/03/defining-javascript-functions/ >> >> Kindly post your feedback. > > Some inaccurracies/mistakes: > > * "Creating a function expression is easy: just declare a function where > the parser expects an expression and it automatically becomes a function > expression." > > The term "declare" might be confusing here, it also indicates a name > which is optional for function expressions. It is not just confusing; it is *wrong*. This is commonly referred to as _defining_ a function. Also, function expressions are not created; _functions_ (Function instances) are created when parsing function expressions that have been _written_. > * "the function body has to be parsed every time it is called." > > A body isn't called, a function is. Of course. Excessive use of “call” is a telltale sign for a script kiddie. > Because of that, the statement is confusing; you should emphasize that the > function body only needs to be parsed when the Function constructor is > called, not every time when the resulting function is called and the body > is executed. Not generally true either. > * "And there are potential risks from malicious agents" > > Those come from *unsafe* construction of dynamic code strings, Meaning? > not from using Function() in general. Hence “potential”. That said, the entire style of the article is as clueless as it is FUD-ish, which is to be expected from a Googlodyte. > * "However for function expressions, the variable declaration is hoisted" > > Not all function expressions appear inside a variable initialisation. Correct. Also, the script-kiddie term “hoisted” implies the misconception that source code would be reorganized; that is not the case. Instead, when control enters an execution context, declarations – function *declarations* and variable declarations alike – are parsed/acted upon before everything else in that context. This only has the effect *as if* code *had been* reorganized; that can be clearly seen with Venkman, the JavaScript™ debugger. The clueful (hacker) has a natural desire to find out how things work; they have studied how things work, hence they know how they work, and how to reuse existing, well-defined terminology to describe that; the clueless (script kiddie) invents new terms out of thin air instead so that they can manage to grasp how and why they perceive things to be, and they parrot terms and statements so as to appear knowledgable to their fellow (clueless). > * if(true) { OMG. > //function expression because > //it is not a source element > function baz() {}; > } > > Nope, that's a syntax error. Expression statements must not begin with > the function keyword. See > http://kangax.github.io/nfe/#function-declarations-in-blocks for more > information As a conforming extension of ECMAScript, several implementations have allowed what is has been dubbed “function statements”. So this is neither an expression statement nor a syntax error per se. For example, it is not a syntax error in Google V8 3.23. But this syntax is incompatible, so to be avoided (called “not ‘safe’” in the ECMAScript Support Matrix). I find your last quotation confusing as it is lacking quotation marks because it is just source code. It would have been better to use “|” for all quotations from sources outside the thread in the first place. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.