js replace 全局替换
"\s"匹配任何不可见字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v],
火狐的web开发指南
https://msdn.microsoft.com/zh-cn/
25+ JavaScript Shorthand Coding Techniques
function sayHello(name) {
console.log('Hello', name);
}
简写为:sayHello = name => console.log('Hello', name);
async函数为 sayHello = async name => console.log('Hello', name);
es6语法:["duck", "cat", "goat"].filter(el => el.length > 3); 输出 ["duck", "goat"]
旧的浏览器可以使用:array.filter(el => {console.log(el); return el.length> 3;})
返回对象字面量(对象参数的值)。箭头函数(Arrow func)要用圆括号把对象字面量包起来:
//ES5
var setNameIdsEs5 = function setNameIds(id, name) {
return {
id: id,
name: name
};
};
// ES6
var setNameIdsEs6 = (id, name) => ({ id: id, name: name });
console.log(setNameIdsEs6 (4, "Kyle")); // Object {id: 4, name: "Kyle"}