[Prototype-core] Re: Syntax question
On Jul 4, 2007, at 10:23 PM, Andrew Dupont wrote: On Jul 4, 1:52 pm, Vincent [EMAIL PROTECTED] wrote: I agree on the multiple declaration syntax, but in the cases above, those variables have already been declared earlier in the code and are simply assigned new values in the reported lines. Yeah, it's a mistake, but it's an innocuous one. SpiderMonkey raises a warning; other engines don't seem to care. That said, this is the sort of syntax thing that I'll correct if I'm writing a patch that touches that code anyway. So this'll eventually get fixed. It's actually not a mistake. See the MDC article on JavaScript's comma operator for an explanation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:Comma_Operator The comma, when used outside of the context of var, joins multiple expressions together and evaluates to the value of the last expression. To see this in action, try entering (console.log(a), console.log(b), 3) + 4 in Firebug. You'll see a and b logged to the console, followed by 7, the value of the entire expression. One handy use for the comma operator is avoiding braces in conditionals whose bodies are simply assigning values to variables. E.g. instead of if (a b) { c = d; e = f; } you can write if (a b) c = d, e = f; -sam smime.p7s Description: S/MIME cryptographic signature
[Prototype-core] Re: Syntax question
You can declare more than one variable at a time via the use of the comma. Look under The Name of a Variable http://www.functionx.com/javascript/Lesson04.htm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Syntax question
On 4 juil, 14:33, jdalton [EMAIL PROTECTED] wrote: You can declare more than one variable at a time via the use of the comma. Look under The Name of a Variablehttp://www.functionx.com/javascript/Lesson04.htm I agree on the multiple declaration syntax, but in the cases above, those variables have already been declared earlier in the code and are simply assigned new values in the reported lines. For example lines 214-226 (in version 1.5.1.1) read : var result = '', source = this, match; // This comma is OK # replacement = arguments.callee.prepareReplacement(replacement); while (source.length 0) { if (match = source.match(pattern)) { result += source.slice(0, match.index); result += String.interpret(replacement(match)); source = source.slice(match.index + match[0].length); } else { result += source, source = ''; // This comma is what puzzles me # } } return result; Thanks for your quick reply. Vincent --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Syntax question
On Jul 4, 1:52 pm, Vincent [EMAIL PROTECTED] wrote: I agree on the multiple declaration syntax, but in the cases above, those variables have already been declared earlier in the code and are simply assigned new values in the reported lines. Yeah, it's a mistake, but it's an innocuous one. SpiderMonkey raises a warning; other engines don't seem to care. That said, this is the sort of syntax thing that I'll correct if I'm writing a patch that touches that code anyway. So this'll eventually get fixed. Cheers, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---