Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created February 16, 2013 01:34
Show Gist options
  • Save OscarGodson/4965027 to your computer and use it in GitHub Desktop.
Save OscarGodson/4965027 to your computer and use it in GitHub Desktop.
// Set multiple vars / obj props to the same value
el.style.width = x;
newWidth = x;
eventData.width = x;
// Set x as the value to these vars / obj props
x => (el.style.width, newWidth, eventData.width);
@techwraith
Copy link

You mean like this?

el.style.width = newWidth = eventData.width = x;

@komatsu
Copy link

komatsu commented Feb 16, 2013

@LeifWarner
Copy link

I thought JavaScript had a kind of multiple-assignment on the left-hand side, but maybe I was thinking of Ruby:
a, b, c = [1,2,3]
CoffeeScript has that destructuring assignment, in the form of:
[a, b, c] = [1,2,3]

I guess I was thinking, (with the addition of a repeat utility method), you could something like
el.style.width, newWidth, eventData.width = repeat(x, 3)
Where repeat just makes an array by repeating x n times.

@bytespider
Copy link

What @techwraith said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment