我有一个符号没有在 IE 中定义,所以我尝试使用这个库作为 polyfill
https://github.com/medikoo/es6-symbol
由于我缺乏经验,我真的不知道如何包含它以便它用作全局。 详细地说,在我的代码中,我使用 requirejs 将其包含为:
requirejs.config({
paths:
{ 'symbol': 'libs/es6-symbol/index' }
})
//define it in app entry point
require([
'symbol'],
function (sy) {
//What should I do?
}
我应该如何处理这个问题?
最佳答案
您不能仅使用 RequireJS 加载 es6-symbol
的 index.js
。如果您只是看一下,您会看到:
'use strict';
module.exports = require('./is-implemented')() ? Symbol : require('./polyfill');
这是有效的 CommonJS
代码,但不是有效的 AMD 代码。 RequireJS 原生支持 AMD,而不是 CommonJS。要将 CommonJS
代码与 RequireJS 一起使用,您至少需要将上面的代码包装在 define
调用中,这意味着有一个构建步骤.
最终,您应该听取 README 的建议:
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack
研究 bundler ,选择一个,为其编写构建配置,如果您仍然遇到问题,可以在此站点上询问。
关于javascript - 如何使用 ES6 符号填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39686507/