How can I feature-detect ES6 generators?

前端 未结 2 576
小鲜肉
小鲜肉 2021-02-13 17:29

I\'m really enjoying ES6 generators. Is there a way I can detect generator support in browsers? I know generators might not be in a lot of browsers (or possible no browsers at a

2条回答
  •  后悔当初
    2021-02-13 17:58

    One of the few times that eval is actually the right solution.

    For language construct changes, you need something like this:

    try {
      eval("(function *(){})");
    } catch(err) {
      console.log(err);
      console.log("No generators");
    }
    

提交回复
热议问题