-
-
Notifications
You must be signed in to change notification settings - Fork 117
我也来推荐一个吧 Intl实例的运用 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
数字格式化那个,更简单是 |
@islishude 哈哈 经你提醒 那我还是把其他的都写上吧 再说我也将localeCompare拼写错了,刚好改正 勿喷 感谢提醒 |
我来贴个测试吧 var suite = new Benchmark.Suite;
suite.add('Intl', function() {
new Intl.NumberFormat().format(123123);
})
.add('toLocaleString', function() {
(123123).toLocaleString('en-US')
})
.add('replace', function() {
String(123123).replace(/(^|\s)\d+/g, s => s.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true }); 输出
测试环境 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exp: 排序'我','爱', 以往我们会用localeCompare进行,但是也可以用
PS: 推荐在字符串超长时,或者长字符串数组时使用
exp: 将1000转化为1,000,这个特性大大有用啊 再也不用自己手写了
PS: 当然也可以使用:
exp: 将时间格式化为2017-12-3
PS: 也可以使用
PS:当然每个都有更加高级的配置,可以自定制,这个太多了,记不住,用的时候再去查就好了,现在赖得去查,各位看官也可以自己去瞅瞅ecmascript文件;
The text was updated successfully, but these errors were encountered: