简体   繁体   English

我如何转换这个箭头函数?

[英]How do I convert this Arrow Function?

I cannot figure out how to convert this arrow function into IE compatible function.我无法弄清楚如何将此箭头函数转换为 IE 兼容函数。 I really appreciate if someone could provide a resolution to this:如果有人可以为此提供解决方案,我真的很感激:

const store = window.WebChat.createStore({}, ({ dispatch }) => next => async action => {
                        if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
                            // Mocking data to be sent
                            const userId = 'xyz789';
                            const payloadUserContext = action.payload;

                            action = window.simpleUpdateIn(
                                action,
                                ['payload', 'activity', 'channelData'],
                                () => ({
                                    'personId': userId,
                                    'domain': $.urlParam('d'),
                                    'environment': window.location.host,
                                    'userContext': payloadUserContext
                                })
                            )
                        }
                        return next(action);
                    });

Just use https://babeljs.io/只需使用https://babeljs.io/

var store = window.WebChat.createStore({}, function (_ref) {
      var dispatch = _ref.dispatch;
      return function (next) {
        return async function (action) {
          if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
            // Mocking data to be sent
            var userId = 'xyz789';
            var payloadUserContext = action.payload;
            action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData'], function () {
              return {
                'personId': userId,
                'domain': $.urlParam('d'),
                'environment': window.location.host,
                'userContext': payloadUserContext
              };
            });
          }

          return next(action);
        };
      };
    });

You can use this online babel transpiler https://babeljs.io/repl (a transpiler is used to convert code from one version to another, in this case we want to go from es6 to es5).您可以使用这个在线 babel 转译器https://babeljs.io/repl (转译器用于将代码从一个版本转换为另一个版本,在这种情况下我们希望从 es6 转到 es5)。

You can check for ES browser support here https://www.w3schools.com/js/js_versions.asp您可以在此处查看 ES 浏览器支持https://www.w3schools.com/js/js_versions.asp


EDIT:编辑:

Messing around with the web, I find out babel produces a result that you probably wouldn't want to use (at least for functions defined with async/await).我在网上闲逛,我发现 babel 产生了一个你可能不想使用的结果(至少对于用 async/await 定义的函数)。

What you can do is transpile with babel, and whatever is left with async/await, change it up to .then and .catch.你可以做的是用 babel 进行转译,而 async/await 剩下的任何东西,把它改成 .then 和 .catch。

For instance,例如,

 const someAsyncRequest = () => new Promise((resolve) => { setTimeout(() => { resolve("Responding") }, 1000) }) const myAsyncFunction = async () => { console.log("Making request") const result = await someAsyncRequest() console.log(result) console.log("Done!") } function myIE9AsyncFunction() { console.log("Making request") someAsyncRequest() .then(function (result) { console.log(result) console.log("Done!") }) .catch(function (error) { console.log("What the... ", error) }) } myAsyncFunction() myIE9AsyncFunction()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM