箭头函数:
- 代码:
let a = (i,j) => { return i + j; }
- 编译为:
var a = function(i, j) { return i + j; };
- 代码:
类:
class A{ constructor(){ console.log(1); } } class B extends A{ constructor(){ super(); } }
字符串模板:
let name = 'lee'; let output = `hello ${name}`;
解构:
let [a,b,c] = [1,2,3]; let func = ({name:x}){ console.log(x); }
获取剩余参数:
let func = (x,...y) => { console.log(y); }
for…of 语法:
const arr = [1,2,3]; for(let item of arr){ console.log(item); }
导入/导出:
- 导出:
export default a; export {a,b};
- 导入:
import a from 'test'; import {a,b} from 'test';
- 导出:
集合/字典:
- 集合:
let obj = new Set(); obj.add("hello").add("goodbye").add("hello"); console.log(obj.size); console.log(obj.has('hello'));
- 字典:
let obj = new Map(); obj.set('num', 1); console.log(obj.get('num'));
- 集合:
字符串/数组/对象:
let str = 'abc'; // 1. 判断 str 中是否包含 'c' console.log(str.includes('c')); // 2. 重复 str 3次 str.repeat(3); console.log(str); let arr = new Array(3); // 3. 将 arr 填充成 7 arr.fill(7); console.log(arr); let obj = {name:'lee'}; // 4. 往 obj 后面添加对象 {gender:'male'} let new_obj = Object.assign(obj,{gender:'male'}); console.log(new_obj);
文档更新时间: 2024-04-20 10:57 作者:lee