r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 20 '24

[deleted] — view deleted comment

10

u/badmonkey0001 Red security clearance Mar 21 '24

wants a string, not an object

Strings are objects in JS. Try this on a console:

"foobar".constructor
// ƒ String() { [native code] }

True, it could check the type of object but obviously it doesn't.

0

u/intbeam Mar 21 '24

Strings are objects in JS

No, strings are strings

type of object

If strings were objects in JS - as in how "objects" work in JS - there would literally be no way to tell a string apart from anything else

JavaScript doesn't have type categories beyond the native ones; you can't define two different types of objects

Don't confuse a universal API with object orientation

4

u/badmonkey0001 Red security clearance Mar 21 '24

No, strings are strings

Strings are object prototypes.

Object.getPrototypeOf("foobar")
// String {'', anchor: ƒ, at: ƒ, big: ƒ, blink: ƒ, …}
"foobar".__proto__
// String {'', anchor: ƒ, at: ƒ, big: ƒ, blink: ƒ, …}

Also from the Mozilla docs:

String

The String object is used to represent and manipulate a sequence of characters.

1

u/intbeam Mar 21 '24

Strings are strings, what you are seeing is an API wrapper, not object orientation

Mozilla and everyone else should stop gaslighting people into making the mistake of believing that JS is an object oriented language

1

u/badmonkey0001 Red security clearance Mar 21 '24

I'm not saying JS is any good for OO or evangelizing anything else about it. JS is a weird monster. It plays loose with nearly all programming concepts.

-8

u/loftwyr Mar 20 '24

That makes perfect sense and should be included in every language everywhere.

11

u/bossrabbit Mar 20 '24

Say sike now

10

u/Smayteeh Mar 20 '24

Yes. Having random characters that I didn’t write and are also not present in the code, but that do modify the behaviour of said code is a very reasonable and sane thing to want.

1

u/El_Impresionante Mar 21 '24

Correct! Even exceptions should be handled by this same technique and the exception message should be used as a representation for the passing the "value" of it.

new RegExp(sdfsd) should return /[sdfsd is not defined]/