Lets say I have an object
const obj = { width: 100, height: 200 }
I wish to pass that object to a method
myFunc( obj );
Inside that method I wish to pull out the height, but at the same time subtract a value. I only wish to do this once and after that it will never change.
Doing the following will get me the correct height I want of say 150.
let {height: localHeight} = obj;
localHeight = localHeight - 50;
How do I do the above in a single line ?
Something like this - but I know this doesn't work.
const { height: (localHeight = localHeight - 50) } = obj
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…