OGeek|极客世界-中国程序员成长平台

标题: javascript - 如何使箭头功能在 IOS 9.3.1 上工作? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:17
标题: javascript - 如何使箭头功能在 IOS 9.3.1 上工作?

我喜欢使用 fetch API 和 ES6 箭头函数,但我很难找到一个在 IOS Safari 9.3.1 上运行的简单示例。

function foobar() {
  fetch("https://httpbin.org/get", {
      method: "GET"
    })
    .catch(() => {
      console.log("Fail zone");
    })
    .then((res) => {
      if (res.ok) {
        res.json().then((json) => {
          document.getElementById("response").innerHTML = JSON.stringify(json, null, 2);
        });
      } else {
        console.log("error", res);
      }
    });
}
<button onClick="foobar(this);">Just testing</button>
<pre id=response></pre>


Best Answer-推荐答案


为了使箭头功能正常工作,我安装了 npm install babel-cli babel-preset-es2015 然后运行:

./node_modules/babel-cli/bin/babel.js --presets es2015 main.js -o compiled.js

关于 IOS 中的 Fetch API 支持,我刚刚找到了 https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js

如果有更好的方法,请告诉我。

关于javascript - 如何使箭头功能在 IOS 9.3.1 上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37096005/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4