Live data from Hacker News

A summary of ECMAScript 6 features

github.com

51–54 of 54 posts

Re: A summary of ECMAScript 6 features

#51
post #50
post #49

Earlier quoted context omitted.

I can't come up with a real world use for the .map function, but then I only use Arrays when I do evil things like writing optimized code. If I however would end up in a situation where I wanted to do: var odds = evens.map(v => v + 1); I would write this instead: var odds = increment(evens, n); But it's never as simple as this, evens would probably be some sort of async object and you probably want to call another fu…

That is a loaded example that deliberately leaves out the implementation details to disguise the productivity gains. If you really can't see the productivity difference between writing this: const vals = ['#hp','#mp','#gp'].map(x => $(x).val()); And this: var elems = ['#hp','#mp','#gp']; var getVal = function (x) { return $(x).val() }; var mtVals = []; for (var x = 0; x ... then maybe you should actually go read some…

I'll try to interpret the code ... You have an array of string values. You use the .map function to iterate through all the strings. For each string you change the string to whatever is returned from $(x).val()

(basically just juggling data, you should make a real world example.)

I have seen Jquery before so I know $ returns a document element. And if you pass # into it, it will return getElementById(). And .val() returns .value

So my guess is that you want to get the values of hp, mp, gp, whatever that is. I don't understand why you want them in an array though!? Wouldn't it be better to store them in an associative array? So that you don't have to remember what position in the array points to what value.

Try this instead:

  var signupForm = getFormData("signupForm");
  alert( "Your name is " + signupForm["name"] );

Or without the abstraction:

  var name = document.getElementById("name").value;
A little more characters to type, but you don't have to learn a framework to know what it does. A trick here is to use keyboard macros to do the boilerplate. Don't var PI = Math.PI because of laziness.

Re: A summary of ECMAScript 6 features

#52
post #51
post #50

Earlier quoted context omitted.

That is a loaded example that deliberately leaves out the implementation details to disguise the productivity gains. If you really can't see the productivity difference between writing this: const vals = ['#hp','#mp','#gp'].map(x => $(x).val()); And this: var elems = ['#hp','#mp','#gp']; var getVal = function (x) { return $(x).val() }; var mtVals = []; for (var x = 0; x ... then maybe you should actually go read some…

I'll try to interpret the code ... You have an array of string values. You use the .map function to iterate through all the strings. For each string you change the string to whatever is returned from $(x).val() (basically just juggling data, you should make a real world example.) I have seen Jquery before so I know $ returns a document element. And if you pass # into it, it will return getElementById(). And .val() re…

A trick here is to use keyboard macros to do the boilerplate.

Yes, I can see my preceding correspondent was correct in discontinuing this engagement. Sorry to have wasted our collective time.

Re: A summary of ECMAScript 6 features

#53
post #52
post #51

Earlier quoted context omitted.

I'll try to interpret the code ... You have an array of string values. You use the .map function to iterate through all the strings. For each string you change the string to whatever is returned from $(x).val() (basically just juggling data, you should make a real world example.) I have seen Jquery before so I know $ returns a document element. And if you pass # into it, it will return getElementById(). And .val() re…

A trick here is to use keyboard macros to do the boilerplate. Yes, I can see my preceding correspondent was correct in discontinuing this engagement. Sorry to have wasted our collective time.

I prefer document.getElementById("myKitten") because it's easier to read and more describing then just $("#myKitten")

If it's too long to type, and you use it often, make a macro for it. When naming stuff, keep it short and simple though.

Also, you shouldn't hide logic behind names. I was actually wrong about evens.map(v => v + 1); If that's what you want to do, then write that. It's a thin line though, it might be hard to know what "v" is in that context.

Re: A summary of ECMAScript 6 features

#54
post #42

This is some scary shit! JavaScript is a mainstream language. That means average people like myself can be very productive with it. It is easy to learn and it's easy to find people who can maintain JS code. But it seems you need to be an academic in programming languages just to figure out what these new features do, and why they are needed. I'm afraid that the rapid development will make it harder to learn the langu…

this is an interesting perspective that I don't really understand and hope you will expand on. Which parts of the es6 changes do you feel you need to be an academic to understand? The es5 spec is 6 years old at this point and it feels to me like es6 is taking forever to be implemented. Most of the changes are there to make things more consistent and reduce pitfalls and edge cases - let and const to solve the problems…

The majority of JS developers do not know what a scope is, what Destructuring and Rest + Spread means, what a generator does, and have never heard of Map + Set + WeakMap + WeakSet.
Post reply on HN