“Intl not available” in Edge 15

♀尐吖头ヾ 提交于 2019-12-22 03:53:14

问题


I'm seeing an Intl not available error in the JS console when my script runs the following code in Edge 15:

new Date().toLocaleDateString()

I'm a bit stumped by this. It is working just fine in Edge 14, and I can't find any reference to the internationalization API suddenly disappearing from Edge 15.

I'm not sure if this is the proper way to test it, but running window.hasOwnProperty("Intl") in the console actually returns true. To me this seems to indicate that Intl actually is there.

Anyone with more JS skills able to tell what is really going on here?


回答1:


Make sure your JS code doesn't redefine standard Map class.

We had almost the same problem, but with Intl.Collator object instead. We couldn't use String.prototype.localeCompare("...", "locale") because of this.

You can look at this codepen in Edge 15 and in other browsers for explanation: https://codepen.io/kgorob/pen/pweaWV.

P.S. I'm not sure your problem is because of Map class specifically, maybe it's some other standard JS class you are re-defining.




回答2:


The problem is because of these lines in Chakracore code. Intl.js is javascript file that is used internally to perform various internationalization specific operations. Since Mapis used, over-writing it before Intl.js code executes (it is executed lazily), causes problem. This should be addressed soon.




回答3:


As ksp's answer says, this is caused by Intl lazy-loading after Map is overwritten. Therefore, the easiest workaround is to just force it to initialise early, before other scripts run:

<html>
  <head>
  <script>Intl.DateTimeFormat</script>
  ...

Here is the issue in the Chakra repo: https://github.com/Microsoft/ChakraCore/issues/3189



来源:https://stackoverflow.com/questions/44303235/intl-not-available-in-edge-15

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!