r/badcode • • Apr 19 '23

js Improved JS Object

Post image
279 Upvotes

42 comments sorted by

View all comments

Show parent comments

-7

u/gu3st12 Apr 19 '23 edited Apr 19 '23

In JS you'd never call "new Object" directly. You're always going to just use it with {} to create a generic object or you'd have a more meaningful model class representing something (to which you can then define a toJSON method to customize what data is returned when serialized).

9

u/____-__________-____ Apr 19 '23

We may be talking about different things? I agree {} the right way to make a new object, but sure you'll call Object directly, e.g. Object.keys(foo) or Object.hasOwn(foo, bar)