我也只是我

文章 评论 浏览 27

我也只是我 2022-05-02 20:52:11

写的牛逼,补充下下面的情况:

function* helloWorldGenerator() {
  const a = yield 'hello';
  return a;
}

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! regenerator-runtime/runtime */ "./node_modules/regenerator-runtime/runtime.js");
/* harmony import */ var regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0__);


var _marked =
/*#__PURE__*/
regeneratorRuntime.mark(helloWorldGenerator);

function helloWorldGenerator() {
  var a;
  return regeneratorRuntime.wrap(function helloWorldGenerator$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          _context.next = 2;
          return 'hello';

        case 2:
          a = _context.sent; // 补充: context 上面还有个比较重要的属性是 sent
          return _context.abrupt("return", a);

        case 4:
        case "end":
          return _context.stop();
      }
    }
  }, _marked, this);
}

ES6 系列之 Babel 将 Generator 编译成了什么样子?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文