Comments (3)
Correct, there are two different use cases. Use new Object()
when you want to many instances with shared functionality. Use {}
for one off objects.
With the style guide, we were just trying to say when you're making a plain object it's preferred you use object literal syntax. to avoid this:
var dragon = new Object();
dragon.firstName = 'fred';
dragon.lastName = 'the dragon';
// preferred
var dragon = {
firstName: 'fred',
lastName: 'the dragon'
};
If you need to use new Object()
to share functionality between different instances, that's okay too.
Here's a great read on the different ways to create objects: Five ways to create objects…
from javascript.
I can't think of any reason it would be a good idea to use new Object()
vs {}
. Now, new MyObject()
is a different story.
from javascript.
new object() works fundamentally very similar to how jquery plugins work. "Create it once and then reimplement over and over again by instantiating". The other option can be a bit clumsy to achieve that use case. At the OS level a new memory block is created for every instance, that will avoid unnecessary use of CPU cycles.
from javascript.
Related Issues (20)
- [spam] HOT 1
- [spam]
- [spam] HOT 1
- Multiline comments HOT 3
- [spam]
- [spam]
- TypeError: Failed to load plugin 'jsx-a11y' declared HOT 4
- [spam]
- [spam] HOT 1
- Regarding Updation HOT 4
- [spam] HOT 1
- [spam]
- Link 404 not found HOT 2
- Can we add on quiz sections on this repo too HOT 11
- [spam]
- eslint v9 support
- [spam]
- import/no-extraneous-dependencies shouldn't be a code style rule HOT 25
- Parsing error: Unexpected character '#' HOT 3
- [spam] HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript.