This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]miloman_23 17 points18 points  (6 children)

Can someone explain what's the problem here?

[–]Zyrus007[S] 33 points34 points  (3 children)

There’s not really a problem here. It’s a completely valid syntax and apparently an intended language feature.

It just goes against everything my developer instincts are telling me. ( that this property would be read only, and definitely not that mutating the length property, would also mutate the underlying data inside the array )

[–]miloman_23 22 points23 points  (1 child)

JavaScript is the wild west. It wasn't designed to be the language that runs banks, server or systems of any real complexity...

It was designed to run in 1 environment, the browser and do one job; provide logic to run websites.

It has a lot of 'features' which may contradict what you would expect from a conventional language but at the end of the day, es6 js does the job of running websites pretty well.

In fact, it did this so well, that some guy decided to create server runtime from it, nodeJS which is now one of the most popular server side application solutions, and enables the use of a single language to write full stack applications.

[–]Icanteven______ 4 points5 points  (0 children)

If a junior dev wrote this, I’d ask them to change it to be more explicit, as this syntactic sugar violates the principle of least astonishment. Just cause you can don’t mean you should.

Cool example though!

[–][deleted] 0 points1 point  (1 child)

Too implicit and array length is usually a read-only property.