在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ transform-runtime 和 babel-polyfill 技術(shù)細節(jié)上

transform-runtime 和 babel-polyfill 技術(shù)細節(jié)上的差異?

Whenever you use a generator function or async function:

function* foo() {

}

the following is generated:

"use strict";

var _marked = [foo].map(regeneratorRuntime.mark);

function foo() {
  return regeneratorRuntime.wrap(function foo$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
        case "end":
          return _context.stop();
      }
    }
  }, _marked[0], this);
}

This isn’t ideal since it relies on the regenerator runtime being included, which pollutes the global scope.

With the runtime transformer, however, it is compiled to:

"use strict";

var _regenerator = require("babel-runtime/regenerator");

var _regenerator2 = _interopRequireDefault(_regenerator);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _marked = [foo].map(_regenerator2.default.mark);

function foo() {
  return _regenerator2.default.wrap(function foo$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
        case "end":
          return _context.stop();
      }
    }
  }, _marked[0], this);
}

This means that you can use the regenerator runtime without polluting your current environment.

有沒有大佬解釋一下上面兩端編譯后的代碼,沒看懂...
另外為什么第一段代碼污染了全局作用域,而第二種沒有。

回答
編輯回答
懶豬

1.因為 regeneratorRuntime在第一種方式里是全局引入的
2.第二種方式里是通過require在當前文件里引入的

個人愚見

2017年9月8日 10:17