What does the ‘…rest’ stand for in this object destructuring?

This is object rest operator, it creates an object from all properties that weren’t explicitly destructured. Note: since object rest/spread is still a stage 3 proposal, and requires a babel transform to work. const obj = { a: 1, b: 2, c: 3}; const { a, …everythingElse } = obj; console.log(a); console.log(everythingElse); It’s equivalent to … Read more

Usage of rest parameter and spread operator in javascript

Is the difference between them is just syntax or there’s a performance issue? Both, and more… Rest parameters: Are a known idiom in other languages (Ruby, Python). Are esier to read and maintain (vs. slice). Are easier to understand for beginners. Can (and likely will) result in better performance, since engines can optimize. Are tool … Read more

Typescript recursive function composition

Circular type aliases are not really supported except in certain cases. (UPDATE TS 4.1, these are more supported now, but I’m still inclined to represent flow() as operating on AsChain that verifies a particular array of functions instead of trying to come up with a Chain that matches all valid arrays of functions) Instead of … Read more

Deep copy in ES6 using the spread syntax

Use JSON for deep copy var newObject = JSON.parse(JSON.stringify(oldObject)) var oldObject = { name: ‘A’, address: { street: ‘Station Road’, city: ‘Pune’ } } var newObject = JSON.parse(JSON.stringify(oldObject)); newObject.address.city = ‘Delhi’; console.log(‘newObject’); console.log(newObject); console.log(‘oldObject’); console.log(oldObject);

Spread Syntax vs Rest Parameter in ES2015 / ES6

When using spread, you are expanding a single variable into more: var abc = [‘a’, ‘b’, ‘c’]; var def = [‘d’, ‘e’, ‘f’]; var alpha = [ …abc, …def ]; console.log(alpha)// alpha == [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]; When using rest arguments, you are collapsing all remaining arguments of a function into one array: … Read more