替换lambda表达式,因为IE不接受它们



我当前在我的数据调用上使用lambda表达式,并且在Chrome上效果很好。我也必须使其在IE上使用,而IE不会接受它们。我使用的代码是:

myApp.factory('User', ['$resource',
function saveDateFactory($resource) {
  var myData = '';
  //this grabs the data we need for the url below
  function getMyData(data) {
    myData = data;
  }
  //this is where we actually capture the data
  return {
    getMyData: getMyData,
    resource: () => $resource(myData, {}, {
      query: {
        method: "GET", params: {}, isArray: true,
        interceptor: {
          response: function (response) {
            //this is the piece we actually need
            return response.data;
          }
        }
      }
    })
  };
}]);

有人对我如何更改它有建议,以便它可以接受并且它仍然有效吗?感谢您的帮助!

您可以在此处检查ES6的IE兼容性。此() =>功能称为ExpressionBodies,不适合IE ....

我建议您不要使用此 ES6 没有解释器的功能,例如 babeljs

myApp.factory('User', ['$resource',
function saveDateFactory($resource) {
  var myData = '';
  //this grabs the data we need for the url below
  function getMyData(data) {
    myData = data;
  }
  //this is where we actually capture the data
  return {
    getMyData: getMyData,
    resource: function(){
        $resource(myData, {}, {
        query: {
          method: "GET", params: {}, isArray: true,
          interceptor: {
            response: function (response) {
              //this is the piece we actually need
              return response.data;
            }
          }
        }
      });
    }
  };
}]);

最新更新