【问题标题】:es6 iterator in codepen sandboxCodepen沙箱中的es6迭代器
【发布时间】:2015-12-11 20:06:18
【问题描述】:

我运行这段代码:

function* quips(name) {
  yield "hello " + name + "!";
  yield "i hope you are enjoying the blog posts";
  if (name.toLowerCase().startsWith("x")) {
    yield "hey, it's cool how your name starts with an X, " + name;
  }
  yield "see you later!";
  yield* quips(name)
}

var meow_iter = quips("Xingu");

showCat();

并捕获一些 referenceError: regeneratorRuntime is not defined - 我做错了什么?

【问题讨论】:

标签: javascript ecmascript-6


【解决方案1】:

这只是showCat 部分。否则它会起作用。

这是一个演示: http://codepen.io/anon/pen/mVeVao?editors=001

(检查浏览器控制台)

如果它仍然不适合你,那么你的浏览器不支持 es6 生成器。添加预处理器(如 babel)应该可以使其工作。进入设置->JS->codepen中的预处理器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 2013-03-19
    • 2013-09-17
    • 2015-06-01
    • 2020-04-14
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多