+ 11

[JavaScript][Need Help] How Can I Make This As ES5 Syntax?

I'm making mini game now. But I have some problem. At the end of game, I want to show players score sorted by value. In ES6 syntax I made ranking like following // my ranking code let rank = Object.entries(D.score).sort((x, y) => y[1] - x[1]).map(v => v.join(' ')).join('\n'); Object.entries(obj) is es6 syntax. If obj is var obj = { a: 3, b: 5, c: 7, d: 3 }; Object.entries(obj) will be [[a, 3], [b, 5], [c, 7], [d, 3]] How can I do as es5 syntax? Please give me any idea. except for-in loop(I hate it)

26th May 2017, 12:02 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
8 Answers
+ 9
@Ben Bright es6 isn't widely supported and users don't care about new syntax. I'm so sad. It has already been more than 2years since es6 syntax was released...
27th May 2017, 5:53 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 8
@Ben Bright thank you but even if I include babel in head tag It doesn't allow me to use es6 syntax. maybe my device has a problem. i dont know why this happens.
26th May 2017, 7:19 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 7
@Ben Bright Thanks. But can I use node packet manager or webpack in Mobile Device? I alwyas code in my tablet or mobile.(My laptop is slow...)
27th May 2017, 5:19 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 7
@Ben Bright Oh no... I think I should mimic entries() method with prototype like.. Object.prototype._entries = function() { //some codes... }; Thanks for your help!
27th May 2017, 5:32 AM
ź¹€ģ •ģ œ(Legacy)
ź¹€ģ •ģ œ(Legacy) - avatar
+ 3
nope you need a computer. coding on mobile or tablet is quite limited.
27th May 2017, 5:26 AM
Benneth Yankey
Benneth Yankey - avatar
+ 3
you are welcome , I see you code all in ES6 that's very good. Modern JS is the future and solves lots of old quirks.
27th May 2017, 5:36 AM
Benneth Yankey
Benneth Yankey - avatar
+ 2
Use JS transpiler or Compiler. I use Babel, Here: https://babeljs.io
26th May 2017, 3:26 AM
Benneth Yankey
Benneth Yankey - avatar
+ 2
no you don't have to include babel in the head tag to make it work. You need to get node js installed and babel CLI through node package manager (npm). If this sounds quite weird to you, I will suggest you go through WebPack tutorials. Get it on youtube or tutorialspoint etc.
26th May 2017, 2:01 PM
Benneth Yankey
Benneth Yankey - avatar