2021 start

  • 早安,所有善良而勇敢的人们
  • 坏人们,颤抖吧

关掉 vue has been registered but not used

package.json 的 eslintConfig(如果已经有 eslintrc.js )

1
2
3
"rules": {
"vue/no-unused-components": "off"
}

clone object 三种

1
2
3
4
5
6
7
let a = {a:1,b:{c:{d:2}}}

{...a}

Object.assign({},a)

JSON.parse(JSON.stringify(food))

via https://www.samanthaming.com/tidbits/70-3-ways-to-clone-objects/

padStart

1
2
3
4
5
6
7
8
9
10
const purchase = [
['Masks', '9.99'],
['Shirt', '20.00'],
['Jacket', '200.00'],
['Gloves', '10.00'],
];

purchase.forEach(([item, price]) => {
console.log(item + price.padStart(20 - item.length));
});

两头对齐

1
2
3
4
Masks           9.99
Shirt 20.00
Jacket 200.00
Gloves 10.00
1
2
3
4
5
const bankNumber = '2222 2222 2222 2222';
const last4Digits = bankNumber.slice(-4);

last4Digits.padStart(bankNumber.length, '*');
// ***************2222

类似滴:

  • trimStart(trimLeft) 去除前空格
  • trimEnd(trimRight) 去除后空格
  • trim() 去除前后空格

shadow copy

  • spread operator {…} […]
  • array slice
  • Object.assign
  • Array.from

deep copy

deep copy (or deep clone): lodash _.cloneDeep, Ramda, a custom function, JSON.parse() / JSON.stringify(), and rfdc

For the best performance, the library rfdc (Really Fast Deep Clone) will deep copy about 400% faster than lodash’s _.cloneDeep

https://medium.com/javascript-in-plain-english/how-to-deep-copy-objects-and-arrays-in-javascript-7c911359b089