phpjavascriptphpjs

JavaScript construct equivalent to PHP's list()?


Possible Duplicate:
Javascript equivalent of PHP's list()

In PHP you can do assignment like this:

list($b,$c,$d) = array("A","B","C");

Is there anything like that in JS?


Solution

  • People seem to hate the with() construct in javascript, but anyway...

    function f(){return {a:1, b:2};}
    with(f()) {
        alert(a);//1
    }
    
    
    // or
    function combine(propertyNames, values) {
        var o = {};
        for (var i=0; i<propertyNames.length; i++) {
            o[propertyNames[i]] = values[i];
        }
        return o;
    }
    
    with (combine(['a', 'b'], [1, 2])) {
        alert(b);//2
    }