T
T
Topsky2017-04-09 22:15:59
Node.js
Topsky, 2017-04-09 22:15:59

Javascript constructor paradox?

I am learning Javascript, in order to create an object, I need to write And as it was described on different sources learn.javascript, habrhabr, toster, stackoverflow that using this construction is a bad form, and it is better to use such a construction I can’t understand why it’s bad? If in any case I need to call the constructor of something somewhere in the code, in this case it is I need a function that returns the current time, but I need to call the constructor, and I remembered why it’s impossible / call badly Can you describe what the problem is Resources, time, something else? --UPDATE No, I don't want to call new Object() everywhere, they just write what is bad/wrong, but I didn't see an explanation why..
var obj = new Object();
var obj = {};
var date = new Date();
new Object()?
new Object()?
Here is an article, translation of the Airbnb JavaScript Style Guide
https://github.com/uprock/javascript#objects
In objects, it is described that var variable = new Object() is bad, and var variable = {} is good, but it is not written why.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hufawoso, 2017-04-09
@Topsky

Because the second one takes up less space in the code. Plus, you can immediately declare properties.
By the way, in js you can declare functions like this:
I don't think it's necessary to explain why it's bad)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question