Prev: FAQ Topic - How can I see in javascript if a web browser acceptscookies? (2010-06-16)
Next: FAQ Topic - How can I see in javascript if a web browser accepts cookies? (2010-06-16)
From: Richard Cornford on 16 Jun 2010 08:25 On Jun 16, 12:49 pm, Thomas 'PointedEars' Lahn wrote: > Asen Bozhilov wrote: <snip> >> foo = [bar, bar = foo][0]; > > That is generic, but the non-obvious code style aside, I would not > want to rely on that it works. The Specifications imply that the > /ElementList/ is evaluated from left to right [11.1.4], but does > it follow that all implementations must do that? The specification doesn't imply that the evaluation order is left to right, it mandates it, or at least that implementations behave as if they do evaluate the element list from left to right, and that order does matter. So it does follow that implementations must do that. > I would also be positively surprised if the creation of an Array > instance, a property lookup and two assignments was more efficient > than a variable declaration and three assignments. So would I, but it should be cheaper than a function call (as that implies the creation of a couple of objects) and if this could be done with a function call (which it cannot) there aren't that many people who would worry about implementing it as one. > That said, I would like very much other implementations to adopt > the desctructuring assignment and ES 6 "Harmony" to specify it. Which itself implies the creation of very temporary objects. Richard.
From: John G Harris on 16 Jun 2010 11:23 On Wed, 16 Jun 2010 at 00:40:06, in comp.lang.javascript, proxygeek wrote: <snip> >Problem: >I need a method swap(a,b) which I can call with two variables as >params and it would swap the values of the two vars. <snip> A way that works in javascript is to switch to a C++ mind-set and tell yourself it's got to be an 'inline' function so it goes faster. Now you copy-and-paste var t = a; a = b; b = t; from a handy text file and change a,b to x,y or whatever is needed at that point in the code. Maybe your source-code editor will make this easier. John -- John Harris
From: Thomas 'PointedEars' Lahn on 16 Jun 2010 11:48 John G Harris wrote: > proxygeek wrote: >> Problem: >> I need a method swap(a,b) which I can call with two variables as >> params and it would swap the values of the two vars. > > A way that works in javascript is to switch to a C++ mind-set and tell > yourself it's got to be an 'inline' function so it goes faster. *g* > Now you copy-and-paste > var t = a; a = b; b = t; > from a handy text file and change a,b to x,y or whatever is needed at > that point in the code. Maybe your source-code editor will make this > easier. Good idea. In fact, in Eclipse JSDT you can define this code template: var ${temp} = ${a}; ${a} = ${b}; ${b} = ${temp};${cursor} (Insert with Ctrl+Space, navigate with Tab.) PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Thomas 'PointedEars' Lahn on 16 Jun 2010 11:54 Richard Cornford wrote: > Thomas 'PointedEars' Lahn wrote: >> Asen Bozhilov wrote: >>> foo = [bar, bar = foo][0]; >> >> That is generic, but the non-obvious code style aside, I would not >> want to rely on that it works. The Specifications imply that the >> /ElementList/ is evaluated from left to right [11.1.4], but does >> it follow that all implementations must do that? > > The specification doesn't imply that the evaluation order is left to > right, it mandates it, or at least that implementations behave as if > they do evaluate the element list from left to right, and that order > does matter. So it does follow that implementations must do that. *Conforming* implementations. Tests pending… >> I would also be positively surprised if the creation of an Array >> instance, a property lookup and two assignments was more efficient >> than a variable declaration and three assignments. > > So would I, but it should be cheaper than a function call (as that > implies the creation of a couple of objects) No doubt about that. > and if this could be done with a function call (which it cannot) there > aren't that many people who would worry about implementing it as one. You've lost me here. >> That said, I would like very much other implementations to adopt >> the desctructuring assignment and ES 6 "Harmony" to specify it. > > Which itself implies the creation of very temporary objects. Yes. Your point being? 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 <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: Lasse Reichstein Nielsen on 16 Jun 2010 12:13
VK <schools_ring(a)yahoo.com> writes: > Not "JavaScript 1.7+" but Mozilla JavaScript 1.7+ thus Gecko platforms > thus 10%-20% of average visitors. JavaScript is the name for the Mozilla (nee Netscape) specified family of languages. Adding "Mozilla" doesn't change anything (and it's not part of the name of the language, that's just "JavaScript 1.7"). > IMO way below the level of an acceptably universal solution. What is the reasonable limit for a universal solution? 100% seems required. (Not that I disagree with the conclusion). > To OP: to my surprise this question seems never was answered properly > in this newsgroup. The only relevant discussion I found was from > 2000: > http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/b72a4c3346057c66/e80dfd68d712c73c > and it doesn't contain any valuablу answer. > > JavaScript as currently defined by ECMA-262 3rd ed. by design doesn't > allow primitives' swap in a separate function, because the function > gets such arguments by values, not by references. Incorrect use of the "JavaScript" name. ECMA-262 doesn't specifiy JavaScript (Mozilla does that). > If your code requires frequent primitive swaps, you may define an > intermediary var at the beginning so do not create it over and over > again and then: > > var swap = null; > // ... > var x = 10, y = 20; > // ... > swap = x, x = y, y = swap; Ick. What's wrong with semicolons now? > window.alert("x = " + x + ", y = " + y); /L -- Lasse Reichstein Holst Nielsen 'Javascript frameworks is a disruptive technology' |