企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1.使用 `let/const`,而非 `var` 来声明变量。 2.使用模板运算符,不必用++来嵌套连接字符串了。需要用 反引号 和字符串插值 `${}` ``` const first = 'Adrian'; const last = 'Mejia'; console.log(`Your name is ${first} ${last}.`); ``` 3.解构赋值 ``` const array = [1, 2, 3, 4]; const [first, ,third] = array; console.log(first, third); // 1 3 ``` 4.类和对象 ``` class Animal { constructor(name) { this.name = name; } speak() { console.log(this.name + ' makes a noise.'); } } const animal = new Animal('animal'); animal.speak(); // animal makes a noise. ``` 5.Promise:用 promise 替代回调地狱 ``` function printAfterTimeout(string, timeout){ return new Promise((resolve, reject) => { setTimeout(function(){ resolve(string); }, timeout); }); } printAfterTimeout('Hello ', 2e3).then((result) => { console.log(result); return printAfterTimeout(result + 'Reader', 2e3); }).then((result) => { console.log(result); }); ``` 6.箭头函数