From: Ry Nohryb on 22 May 2010 18:56 On May 23, 12:19 am, David Mark <dmark.cins...(a)gmail.com> wrote: > (...) > > It's not so much about "trying so hard to be clever" as it's about > > feeling the joy of using the language to its fullest. > > Whatever. From a business standpoint, your joy couldn't be any less > relevant. (...) What's this, comp.lang.javascript.business, or what ? -- Jorge.
From: David Mark on 22 May 2010 19:01 Ry Nohryb wrote: > On May 23, 12:19 am, David Mark <dmark.cins...(a)gmail.com> wrote: >> (...) >>> It's not so much about "trying so hard to be clever" as it's about >>> feeling the joy of using the language to its fullest. >> Whatever. From a business standpoint, your joy couldn't be any less >> relevant. (...) > > What's this, comp.lang.javascript.business, or what ? Well, who do you write programs for? Yourself?
From: Andrea Giammarchi on 23 May 2010 09:23 I don't understand the whole "arguments" flame, neither how you guys ended up talking about ternary and other operators ... anyway ... all I've provided in my first post was a description, with all common matters (e.g. arguments, compressors and the usage of "this", the shadowed constructor, etc) Next, just my 2 cents for those "patience" enough to at least read a post 'till the end before they start replying randomly bulling and bullshitting around ... @Dmitry, I agree about the "new function(argum, ents) { ... }" , but in a 1 to 1 pattern "challenge" it was worth it to mention that: if for semantic reasons we would like to "mark" outer scope variables used internally, we can re-assign named arguments *or* as already mentioned, we can pass directly arguments at the end. The reason I did not mention is that a singleton is usually complex enough to do not fit into few lines and I agree about the scroll down/ up problem (I still use this pattern to preserve an extra "var" when it is possible, choosing semantic arguments names) In any case, being the pattern a Singleton, the cost is absolutely relative and surely less greedy than whatever framework library we use to define a Singleton (those weird things used "somewhere" such ...) var o = new Class(function(){ return { ... proto .... }; }()), o = new o ; About bytes and re-assigned arguments, being the usage of "var" quite inevitable if we need a closure to define a singleton rather than just a literal "{...}", no bytes will be saved for compilers so, as demonstration, it may works, but as provided functionality, it is not convenient. At the same time, if the matter is an undefined argument performance impact, because it is assigned twice, I would explain properly the difference between these 2 patterns you wrote after: On May 22, 5:58 pm, "Dmitry A. Soshnikov" <dmitry.soshni...(a)gmail.com> wrote: > > a && b(); > a = a || b; > in the first case we have a shortcut for a classic if (a) { b(); } fair enough, in the second case we have *double* assignment that is completely useless The right pattern in that case is this: a || (a = b); the difference is that "a" is not assigned to itself if it does not point to a falsy value and the readability is not compromised (we have an extra byte there tho) On NewExpression, I still believe it's a valid option, somehow more elegant and readable for the singleton pattern when a closure is necessary while the module pattern requires a "return" plus extra parenthesis VS just a "new" // module way var o = (function () { return {}; }()); // NewExpression var o = new function () { }; // module way via compressors var o=function(){return{}}(); // NewExpression via compressors var o=new function(){}; now, where is exactly the confusion there? I can't see it at all Best Regards, Andrea Giammarchi
From: Andrea Giammarchi on 23 May 2010 09:33 On May 22, 8:27 pm, "Dmitry A. Soshnikov" <dmitry.soshni...(a)gmail.com> wrote: > > (fun (X) -> 2 * X end)(10). % results 20 > > ah ah, the classic "lambda", I could not resist :D function L(body){ var i = body.indexOf(":"); return ~i ? Function(body.slice(0, i), "return " + body.slice(++i)) : Function("return " + body) ; } L("x:2*x")(10); Br, Andrea Giammarchi
From: Andrea Giammarchi on 23 May 2010 09:45
just in case somebody would like to use it, 99 bytes version with mandatory arguments (the only reason I would use a lambda, no arguments does not make sense) function L(b){var i=b.indexOf(":");return Function.call(this,b.slice(0,i),"return "+b.slice(++i))}; L("x,y:x*y")(2,3); // 6 Br, Andrea Giammarchi |