var a = [1, 2, 3];
var b = a;
a = [];
console.log(a); // []
console.log(b); // [1,2,3]
a = []
方式清除 a 变量数组引用其变量 b 的数组不变
/** | |
* 生成指定位数的随机数 | |
* @param {number} x | |
*/ | |
export const randomStr = (x) => { | |
let s = ""; | |
while(s.length < x && x > 0){ | |
let v = Math.random() < 0.5 ? 32 : 0; | |
s += String.fromCharCode(Math.round(Math.random() * ((122 - v) - (97 - v)) + (97 - v))); | |
} |
let num = 123456.1234 | |
num.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' }) | |
// ¥123,456.12 | |
num.toLocaleString('en-US', { style: 'currency', currency: 'USD' }) | |
// $123,456.12 | |
num.toLocaleString('zh', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }) | |
// 123,456.12 |
" 显示行号 | |
set number | |
" 显示标尺 | |
set ruler | |
" 历史纪录 | |
set history=1000 | |
" 输入的命令显示出来,看的清楚些 |
const UniversalUser = universal(() => import('./User'), { | |
resolve: () => require.resolveWeak('./User'), | |
loading: <Loading /> | |
}) | |
const User = ({ loading, error, user }) => | |
<div> | |
<UniversalUser isLoading={loading} error={error} user={user} /> | |
</div> |
$vu_base: 375 // iphone6 | |
@function vu($px) { | |
@return ($px / $vu_base) * 100vw | |
} |
const bcrypt = require('bcrypt') | |
const jwt = require('jsonwebtoken') | |
const config = require('../config/security') | |
function hashPassword(password) { | |
return new Promise((resolve, reject) => { | |
bcrypt.genSalt(config.saltRounds) | |
.then(salt => { | |
return bcrypt.hash(password, salt) | |
}) |
const container = document.getElementById('js-list'); | |
if (!container) { | |
return | |
} | |
const total = 10000 | |
const batchSize = 4 // 每次插入多少个结点,越大越卡 | |
const batchCount = total / batchSize // 插入次数 | |
let batchDone = 0 // 已经完成的批处理个数 |
const arr = ['aaa', 'bbb', 'aaa', '111']; | |
const uniqueArr = arr.filter((item, index) => { | |
return arr.indexOf(item) === index; | |
}); | |
console.log(uniqueArr); // ['aaa', 'bbb', '111'] | |
const simpleUnique = function(arr) { | |
return [...new Set(arr)] | |
} |
const arr = [ | |
{"name": "Kate", "age": 22}, | |
{"name": "Candy", "age": 21}, | |
{"name": "Petty", "age": 20} | |
]; | |
arr.sort(compare('name')) // {"name": "Candy", "age": 21}, {"name": "Kate", "age": 22}, {"name": "Petty", "age": 20} | |
arr.sort(compare('age')); // {"name": "Petty", "age": 20}, {"name": "Candy", "age": 21}, {"name": "Kate", "age": 22} | |
function compare(key) { |
var a = [1, 2, 3];
var b = a;
a = [];
console.log(a); // []
console.log(b); // [1,2,3]
a = []
方式清除 a 变量数组引用其变量 b 的数组不变