Live data from Hacker News

Overview of JavaScript ES6 features

adrianmejia.com

171–180 of 250 posts

Re: Overview of JavaScript ES6 features

#171
I always turn to an ES6 article on babeljs.io when I check out ES6 features.

https://babeljs.io/docs/learn-es2015/

One of the features I like is default parameters. I'd like to add a usage that isn't mentioned in the article. It's really handy to pass optional parameters since default parameters can be nested.

    class Hoge {
      foo({active=true, collapsed=false, silent=false}={}) {
      }
    }
    
    let hoge = new Hoge();
    hoge.foo({collapsed: true});

Re: Overview of JavaScript ES6 features

#172

Earlier quoted context omitted.

const x = Object.freeze({ y: { foo: 'bar' } }); x.y.foo = 'baz' console.log(x.y.foo) //baz immutablejs might be overkill, but not having, and using, a recursive freeze is going to bite a lot of people if the advice is just 'const + Object.freeze'.

> immutablejs might be overkill, but not having, and using, a recursive freeze is going to bite a lot of people if the advice is just 'const + Object.freeze'. No one should be trying to use a recursive freeze (if they are I would argue their data structure is poorly suited to be immutable). I'm not saying `const` + `Object.freeze()` gets you Immutablejs I'm saying it gets you, likely, what you want / need.

Our team was just hit with this:

  const x = Object.freeze([
    {id: 1, value: 'foo'},
    {id: 2, value: 'bar'},
    {id: 3, value: 'baz'},
  ])

  ...

  //Bug in the code
  x[0].value = 'test'
First comment on the bug report was:

'This shouldn't be possible as the array is const and frozen'.

their data structure is poorly suited to be immutable

An array of object seems completely reasonable. Even an array of objects, where those objects themselves have keys which are objects/arrays doesn't seem unreasonable.

We'll just have to agree to disagree.

Re: Overview of JavaScript ES6 features

#174

The most interesting part about template strings was skipped over: tagged template literals. You can prefix a template string with a function which will get called with the list of string parts and the values passed in ${...} parts, and then it's up to the function to choose how to join the values up into the resulting string (or hell, you could make it return something besides a string if you want). The function can…

How does this work? I can't find any examples and I also don't really understand what mechanism makes your npm module work.

Re: Overview of JavaScript ES6 features

#175
post #148
post #33

Earlier quoted context omitted.

It's both amazing, and 600MB worth of dependencies. We use it for server-side code. It's high quality, and we only have a few issues with it, but I can't wait to be able to ditch is (pretty much when async/await lands in a stable node).

Doing du -ch ./babel* from my `node_modules` directory yields 3.2M total so I'm gonna need a citation on that 600MB claim.

537M here. babel* matches the following packages:

node_modules/babel node_modules/babel-core node_modules/babel-eslint node_modules/babel-plugin-array-includes node_modules/babel-plugin-transform-runtime node_modules/babel-preset-node5 node_modules/babel-register node_modules/babel-runtime

Of course you can just pretend I'm lying.

Re: Overview of JavaScript ES6 features

#176
post #130

Earlier quoted context omitted.

It's spelled out pretty well in the article. But if you want another example, consider these two code blocks: var foo; var bar; { let foo = "hello"; var bar = "world"; } console.log(foo); console.log(bar); This produces: undefined world The reason being that the `let` statement restricted that variable to the block it was in (defined by the { and }). `var` declares the variable globally, allowing it to be accessed ou…

From the article-- let x = 'outer'; function test(inner) { if (inner) { let x = 'inner'; return x; } return x; // gets result from line 1 as expected } test(false); // outer test(true); // inner This makes it seem like let creates global variables. Why would you want to return a variable from outside the function? Doesn't that create massive overhead in terms of keeping track where variables are initially set? Easy t…

[deleted]

Re: Overview of JavaScript ES6 features

#177
post #148

Earlier quoted context omitted.

Doing du -ch ./babel* from my `node_modules` directory yields 3.2M total so I'm gonna need a citation on that 600MB claim.

Admittedly, if you're using a flat structure like NPM3 does, then everything else is at the same level :)

It caught those! doing `du -ch ./babel` says it's only 20k, babel-core is 148k, and babel-cli is 104k.

Re: Overview of JavaScript ES6 features

#178

"best practices": "use class instead of manipulating prototype directly" Who comes up with these "rules"? This is not a hard and fast rule. Manipulating the prototype of an object is not "dangerous". I'm sick and tired of some loud mouth saying something is dangerous without explaining why. WHY? Why it it dangerous? Don't talk at me. Provide me a sound reason and case to justify what you say. Talk is cheap. It makes…

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

This has some warnings at the top as to why.

Re: Overview of JavaScript ES6 features

#179
post #175
post #148

Earlier quoted context omitted.

Doing du -ch ./babel* from my `node_modules` directory yields 3.2M total so I'm gonna need a citation on that 600MB claim.

537M here. babel* matches the following packages: node_modules/babel node_modules/babel-core node_modules/babel-eslint node_modules/babel-plugin-array-includes node_modules/babel-plugin-transform-runtime node_modules/babel-preset-node5 node_modules/babel-register node_modules/babel-runtime Of course you can just pretend I'm lying.

I believe that you're getting that number, but there might be something wrong with your install. I just installed all of those packages and ended up at 6MB.

Re: Overview of JavaScript ES6 features

#180

Earlier quoted context omitted.

> Is it just me, or is Javascript (and more generally, all front end technology) more susceptible to these trivial holy wars? - Tabs vs spaces. - Vi vs Emacs - Weak vs strong typing - where to place {} in block statements - where to put commas No, programming in general is susceptible to these trivial holy wars.

Vi vs Emancs? Weak vs strong typing?? tabs vs spaces??? where did you get those?? The ONLY holy war in JS is the semi-colon one

That's what OP is saying: programming has plenty of holy wars that predate JavaScript.
Post reply on HN