The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Ravager (4) [Avatar] Offline
#1
A.6 Clone with assign()
Would it be beneficial to explain that Object.assign() only does a shallow copy?

const myObject = { name: 'Mary', lastName: 'Smith', birth: { date: '18 Jan 2019' }}
const clone = Object.assign({}, myObject)

console.log(clone.birth.date)  // => 18 Jan 2019
myObject.birth.date = '20 Jan 2019'
console.log(clone.birth.date)  // => 20 Jan 2019


A.8 Destructuring arrays
Would it be helpful to point out that the rest operator can only be used at the end?

let customers = ["Smith", "Clinton", "Lou", "Gonzales"];

let [firstCust, ...otherCust, lastCust] = customers;
// OR: let [...otherCust, lastCust] = customers;

// [ts] A rest element must be last in a destructuring pattern. [2462]


A.14 Chaining promises
Should it be explained that if the catch() callback does not return a rejected Promise or throw an error, then the resulting Promise is fulfilled (and if you don't return a value, it's fulfilled with a value of undefined)?

var result = Promise.reject('FAIL').then((value) => console.log(value)).catch((err) => console.error(err))
// Console: FAIL

result.then((value) => console.log('pass', value)).catch((err) => console.error('fail', err))
// Console: pass undefined


Yakov Fain (219) [Avatar] Offline
#2
Thank you for this great input!