简体   繁体   English

阵列比较可在Chrome中使用,但不适用于Chrome IPAD

[英]Array comparison working in Chrome but not with Chrome IPAD

I am using new_array.filter(val => !old_array.includes(val)); 我正在使用new_array.filter(val =>!old_array.includes(val)); method to compare two array. 比较两个数组的方法。 It works fine in Chrome but not with chrome in IOS. 在Chrome浏览器中工作正常,但在IOS中无法与Chrome浏览器一起使用。 Seems like and issue in => operator. 似乎在=>运算符中发出。 Unfortunately debug mode is not available in IPAD which I am having. 不幸的是,调试模式在我拥有的IPAD中不可用。 Is there any alternate for this. 是否有其他替代方法。

Sathya 萨提亚

Yes. 是。 The alternative is not to use arrow functions (at least, not in the deployed version), which are a fairly new feature (although I'm very surprised to hear that Chrome for iOS doesn't support them; Chrome's underlying JavaScript engine has supported them for a long time). 替代方案是不使用箭头功能(至少不是在已部署的版本中),这是一个相当新的功能(尽管我很惊讶地听到Chrome for iOS不支持它们; Chrome的底层JavaScript引擎已支持他们很长一段时间)。

To do that, you have two options: 为此,您有两种选择:

  1. Transpile with a tool like Babel before you create the deployed version. 在创建已部署的版本之前,请使用Babel之类的工具进行转换。 That way you can happily use arrow functions and many (though not all) other features of ES2015 and after without worrying about support on older browsers. 这样,您就可以愉快地使用箭头功能和ES2015的许多(尽管不是全部)其他功能,而不必担心对旧版浏览器的支持。

  2. Or to just address that one specific thing, use a function function: 或仅解决某一特定问题,请使用function function:

     new_array.filter(function(val) { return !old_array.includes(val); }); 

    You're not using this or super or similar that you need to close over in the callback, so it doesn't have to be an arrow function. 您不需要在回调中使用需要关闭的thissuper或类似对象,因此它不必是箭头函数。

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

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