Tuesday, April 04, 2006

Comma operator in ECMA script

From this page:
Enter a technique I discovered out of necessity, which I call "one-time use expression()". It relies upon the rarely used comma operator in ECMAScript. The expression expr1, expr2 evaluates both expressions, but returns only the value of the second. So we do 2 things inside expression() using this. The first being our dirty deed, secretly inserting markup into the header. The second removes the mechanism we utilized itself! We simply set the value of the property to "none", overriding the current expression() value. It goes away, but leaves the inserted markup. This hack effectively allows "CSS" (I'll use the term loosely) content-generation in IE4+ in Windows! The limitation being, of course, that one must have scripting enabled. Some have told me that expression() works with scripting disabled (that would be a serious security issue in IE, which wouldn't be surprising in the least), however my tests seem to indicate otherwise.


I had seen this done in IE expressions before, but had never seen an explanation of how/why it worked. Firing up Flash to see if the comma operator works in ActionScript...

...and it does!! Really cool! I can see the uses for the comma operator as a shortcut syntax, and perhaps as a weak-strength obfuscation technique, but aside from IE expressions, I can think of no other practical use for it. Everything you can do with it can already be done with other, more maintainable techniques. Am I missing something??

Was this post helpful to you? If so, please consider making a small donation to keep this blog going.

0 Comments:

Post a Comment

<< Home