美文网首页
es6知识整理

es6知识整理

作者: 有一个程序媛 | 来源:发表于2018-04-18 14:51 被阅读0次

1.箭头函数需要注意的地方

        *当要求动态上下文的时候,就不能够使用箭头函数,也就是this的固定化。

        (1)在使用=>定义函数的时候,this的指向是定义时所在的对象,而不是使用时所在的对象;

        (2)不能够用作构造函数,这就是说,不能够使用new命令,否则就会抛出一个错误;

        (3)不能够使用arguments对象;

        (4)不能使用yield命令;

        class Animal {

          constructor() {

            this.type = "animal";

          }

          say(val) {

            setTimeout(function () {

              console.log(this); //window

              console.log(this.type + " says " + val);

            }, 1000)

          }

        }

        var animal = new Animal();

        animal.say("hi"); //undefined says hi

        class Animal {

          constructor() {

            this.type = "animal";

          }

          say(val) {

            setTimeout(() => {

              console.log(this); //Animal

              console.log(this.type + ' says ' + val);

            }, 1000)

          }

        }

        var animal = new Animal();

        animal.say("hi"); //animal says hi

2.promise

        var promise = new Promise((resolve, reject) => {

          if (操作成功) {

            resolve(value)

          } else {

            reject(error)

          }

        })

        promise.then(function (value) {

          // success

        }, function (value) {

          // failure

        })

        setTimeout(function () {

          console.log(1)

        }, 0);

        newPromise(function executor(resolve) {

          console.log(2);

          for(vari = 0; i < 10000; i++) {

            i == 9999 && resolve();

          }

          console.log(3);

        }).then(function () {

          console.log(4);

        });

        console.log(5);------------------------------2 3 5 4 1

相关文章

  • 004_ES6知识点总结(01)let及const声明

    ES6知识点整理 近期准备面试,把ES6的内容详细复习一遍整理来源素材:阮一峰《ES6标准入门》(第三版);htt...

  • react新手必须懂得es6的基础知识

    笔者这两天在整理react知识点的时候,顺便对es6的基础知识也进行了一些整理,其实es6出来已经很久了,也不算是...

  • es6知识整理

    1.箭头函数需要注意的地方 *当要求动态上下文的时候,就不能够使用箭头函数,也就是this的固定化。 (1)在使用...

  • es6知识整理

    虽然es5之前的js用的比较习惯,但是现在es6对于新的框架,比如vue来说用的比较普遍,所以不能总停留在过去,也...

  • 007_ES6知识点总结(04)函数的拓展

    ES6知识点整理 [toc] 04 函数的拓展 04.1 函数参数的默认值 ES6支持函数定义时,直接在参数定义后...

  • ES6部分常用知识整理

    在这整理了一些常用的ES6的知识,希望能够帮助开发者更加了解和运用ES6关注我的个人博客:pinbolei.cn,...

  • ES6零碎知识点回顾

    整理一下ES6相关的知识点 ES6默认开启严格模式 严格模式在es5中就已经有了,但是是可选的.在es6中,一定是...

  • 006_ES6知识点总结(03)字符串的拓展

    ES6知识点整理 [toc] 03 字符串的拓展 03.1 字符的Unicode表示法 略 03.2 codePo...

  • ES6 知识点整理

    ES6 包括 变量、函数、数组、json、字符串、面向对象、promise、generator、async/awa...

  • 2018-04-21

    ES6数组的扩展整理

网友评论

      本文标题:es6知识整理

      本文链接:https://www.haomeiwen.com/subject/albvkftx.html