PhoneNumber.js
PhoneNumber.js copied to clipboard
Error with `let is a reserved identifier` in browser.
Maybe I'm missing the purpose of this lib? Not using it correctly?
Is it meant for node.js?
If I remove strict mode, in Chrome I'm now getting
Undefined identifier
line 109 of PhoneNumber.js
In Firefox without strict mode I'm getting missing ; before statement
It should work. We are using it in gecko: https://hg.mozilla.org/mozilla-central/file/2673016e7df4/dom/phonenumberutils/PhoneNumber.jsm
This SO post should clarify it http://stackoverflow.com/questions/14331617/using-let-and-yield-in-firefox
This raises an interesting question. Would you be willing to add non-spidermonkey engines support? If so, what method would you prefer?
Does simply replacing let and const with var ok?
Last I saw, let and const are supported by V8. In node you can access them using --harmony.
Supported in Node.js v11 which is unstable. It's also about other/older browser engines.
I guess you could also transpile it. ES6 should be in a fairly stable position in 3 months. Stable enough for people to start writing ES6 code and transpiling it for older browsers.
I'm talking about a change in this repository to let people use it, pain-free. We could add a transpiling build task but using a transpiler just to replace const/let with var sounds expensive.
I am ok with replacing let with var. Please submit a pull request.
please see PR #31
I created a fork of PhoneNumber.js that runs even on IE6 - PhoneNumber.js for the Web.
Had to do the following adjustments:
-
const
->var
-
let
->var
-
Object.create(null)
->{}
- removed getters from NationalNumber, precalculated all the needed values instead
-
Array.isArray(z)
->Object.prototype.toString.call(z) == "[object Array]"
-
number[0]
->number.charAt(0)
(only needed in IE6, not in newer browsers) - removed some trailing commas (also updated xml2meta.py to skip the last comma in the output)
I also ported all the existing tests to Qunit test cases and the tests passed in every browser I checked.