ArtLung

February 21st, 2007

Destructured Assignment in Ruby, PHP, and JavaScript

Stupid Code Tricks:

Ruby http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#assign

foo, bar = [1, 2]

PHP http://www.php.net/manual/en/function.list.php

list($foo, $bar) = array(1, 2);

JavaScript http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#Destructuring_assignment

[foo, bar] = [1, 2];  // I believe this is only valid in the latest versions of Firefox.

Leave a Reply