Skip to content

Instantly share code, notes, and snippets.

@Prajjwal
Last active June 30, 2017 11:13
Show Gist options
  • Save Prajjwal/67834eb66d8b3971bfaccdaa73da3ed1 to your computer and use it in GitHub Desktop.
Save Prajjwal/67834eb66d8b3971bfaccdaa73da3ed1 to your computer and use it in GitHub Desktop.
Helper to mimic the ES7 spread operation on Objects
// Or any object that yields a set of { key: value } pairs.
const x = {
* [Symbol.iterator] () {
yield { done: false, value: { dog: 'cat' } }
yield { done: false, value: { dawg: 'cayt' } }
}
}
function ES7ObjectAssign (target, source) {
for (const sourceObject of source) {
Object.assign (target, sourceObject.value)
}
return target
}
console.log (ES7ObjectAssign ({ }, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment