日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)百度小程序教程:esnext
  • esnext
    • let & const
    • 箭頭函數(shù)
    • 更簡(jiǎn)潔的對(duì)象字面量(enhanced object literal)
    • 模板字符串(template string)
    • 解構(gòu)賦值(Destructuring)
    • Default + Rest + Spread

    esnext

    SJS 支持部分 ES6 語法。

    let & const

    代碼示例

    在開發(fā)者工具中打開

    在開發(fā)者工具中打開

    在 WEB IDE 中打開

     
     
     
    1. // demo.sjs
    2. function foo(){
    3. let str = 'hello sjs';
    4. if (true) {
    5. let count = 2;
    6. }
    7. // hello sjs
    8. console.log(str);
    9. // 引用錯(cuò)誤:count 未定義
    10. console.log(count);
    11. }

    箭頭函數(shù)

    代碼示例

    在開發(fā)者工具中打開

    在開發(fā)者工具中打開

    在 WEB IDE 中打開

     
     
     
    1. // demo.sjs
    2. const arr = [1, 2, 3];
    3. const double = x => x * 2;
    4. // output: [2, 4, 6]
    5. console.log(arr.map(double));
    6. var obj = {
    7. birth: 1970,
    8. getAge() {
    9. const b = this.birth;
    10. const fn = () => new Date().getFullYear() - this.birth;
    11. return fn();
    12. }
    13. };
    14. obj.getAge();

    更簡(jiǎn)潔的對(duì)象字面量(enhanced object literal)

    代碼示例

    在開發(fā)者工具中打開

    在開發(fā)者工具中打開

    在 WEB IDE 中打開

     
     
     
    1. var num = 1;
    2. var obj = {
    3. // 對(duì)象屬性
    4. num,
    5. // 對(duì)象方法
    6. printNum() {
    7. console.log(num);
    8. }
    9. };
    10. // 1
    11. obj.printNum();

    :不支持super關(guān)鍵字,不能在對(duì)象方法中使用super

    模板字符串(template string)

     
     
     
    1. const NAME = 'sjs';
    2. // hello sjs
    3. const msg = `hello ${NAME}`;

    解構(gòu)賦值(Destructuring)

    代碼示例

    在開發(fā)者工具中打開

    在開發(fā)者工具中打開

    在 WEB IDE 中打開

     
     
     
    1. // array 解構(gòu)賦值
    2. var [a, ,b] = [1, 2, 3];
    3. // true
    4. a === 1;
    5. // true
    6. b === 3;
    7. // 對(duì)象解構(gòu)賦值
    8. let { foo , bar } = { foo: 'aaa', bar: 'bbb' };
    9. // foo = 'aaa'
    10. // bar = 'bbb'
    11. // 函數(shù)參數(shù)解構(gòu)賦值
    12. // 1.參數(shù)是一組有次序的值
    13. function f1([x, y, z]) {
    14. // 1
    15. console.log(x);
    16. // 2
    17. console.log(y);
    18. // 3
    19. console.log(z);
    20. }
    21. f1([1, 2, 3]);
    22. // 2.參數(shù)是一組無次序的值
    23. function f2({x, y, z}) {
    24. // 1
    25. console.log(x);
    26. // 2
    27. console.log(y);
    28. // 3
    29. console.log(z);
    30. }
    31. f2({z: 3, y: 2, x: 1});
    32. // 解構(gòu)賦值默認(rèn)值
    33. var [a = 1] = [];
    34. // true
    35. a === 1;
    36. // 函數(shù)參數(shù):解構(gòu)賦值 + 默認(rèn)值
    37. function r({a, b, c = 3, d = 4}) {
    38. return a + b + c + d;
    39. }
    40. // true
    41. r({a: 1, b: 2}) === 10;

    Default + Rest + Spread

    代碼示例

    在開發(fā)者工具中打開

    在開發(fā)者工具中打開

    在 WEB IDE 中打開

     
     
     
    1. // 1. Default
    2. function f1(x, y = 2) {
    3. // 如果不給y傳值,或者傳值為undefied,則y的值為12
    4. return x + y;
    5. }
    6. // true
    7. f1(1) === 3;
    8. // 2. Rest
    9. function f2(x, ...arr) {
    10. return x * arr.length;
    11. }
    12. // true
    13. f2(3, 'hello', 'sjs') === 6;
    14. // 3. Spread
    15. function f3(x, y, z) {
    16. return x + y + z;
    17. }
    18. // 數(shù)組解構(gòu)
    19. f3(...[1,2,3]) == 6;
    20. // 4. Rest + Spread
    21. // 數(shù)組解構(gòu)賦值, b = [2, 3]
    22. const [a, ...b] = [1, 2, 3];
    23. // 對(duì)象解構(gòu)賦值, other = {d: 2, e: 3}
    24. const {c, ...other} = {c: 1, d: 2, e: 3};
    25. // 對(duì)象解構(gòu) f = {d: 2, e: 3}
    26. const f = {...other};

    當(dāng)前文章:創(chuàng)新互聯(lián)百度小程序教程:esnext
    文章路徑:http://www.5511xx.com/article/cddiojp.html