I have seen this in a piece of JS code:
var {status, headers, body} = res;
What does it do?
I have seen this in a piece of JS code:
var {status, headers, body} = res;
What does it do?
nice method to set few variables at once from an object (open firebug and paste this to console)
var status=4;
var headers=4;
var body=4;
var res = {status:1, headers:2, body:3};
window.alert(status);
var {status, headers, body} = res;
window.alert(status);
Looks like a destructuring attempt on a variable named res
. I've never seen that in Javascript and Chrome console suggests that it's an error:
> var res = [ 1, 2, 3 ];
> var {status, headers, body} = res;
SyntaxError: Unexpected token {
Firebug console on Firefox 4b12 doesn't complain however but the statement seems to have no effect:
> var res = [ 1, 2, 3 ];
> var {status, headers, body} = res;
> status
undefined
> headers
undefined
> body
undefined