Conversation

the amount of my life that has been lost to "javascript just lets you do shit without throwing any errors or warnings"

1
1
1

im becoming a c programmer after this at least c issues are exciting

2
0
1

i will concede im pretty sure i see why this works (my guess is that this is how 'this' works) but i also hate it

4
1
1

@kirakira wait maybe i’ve spent too much time doing javascript but is the current disgust coming from the fact that you can add properties to an already instantiated object? i fully admit im dumb and may be missing it but im also curious neofox_floof

3
0
2

@rowan @kirakira The way to think about JS objects is that they are not really class-based at all. Any class structure is syntactic sugar.

1
0
0

@rowan yes that, here i am wanting to subscript a thing in a thing but i subscripted the thing & went on a big dumb adventure to figure out what was wrong ~w~

1
0
2

eli, vampire kitsune

Edited 6 months ago
small js infodump, sorry
Show content

@kirakira ES6 classes are not exactly the same but bear significant resemblance to constructor functions. for sake of simplicity, it’s easiest to say that ES6 classes are syntactic sugar on top of constructor functions. the major difference is that classes throw an error when attempting to construct them without the new keyword while a constructor function will have a corrupted state (notably, it will inherit the globalThis as its own this).

the following declarations are nigh-identical

class bitchA {}

function bitchB() {
  if (!new.target) {
    throw new TypeError("calling bitch constructor without new is invalid")
  }
}
2
0
3

@bersl2 @rowan are they just sparkling dicts

2
0
0

eli, vampire kitsune

Edited 6 months ago
re: small js infodump, sorry
Show content

@kirakira both of them produce an Object, which is the same one you get when you use the object literal ({ foo: 1 }) syntax. these are all mutable by default (unless if you use one of the metaprogramming functions like Object.freeze or, more specifically, Object.preventExtensions which stops new properties from being added to an object)

0
0
2

@kirakira neofox_pat_sad you’re a real js programmer now (i’m sorry)

0
0
4
re: small js infodump, sorry
Show content

@kirakira side note: strict mode fixes the globalThis issue in constructor functions

1
0
2

@kirakira @rowan From a certain point of view, yes, but you get a lot of sparkle, much more than something like blessed hashes in Perl.

0
0
0
re: small js infodump, sorry
Show content

@rowan i am learning so much :3

0
0
2

@kirakira @bersl2 @rowan that + the prototype chain to look up parent dicts

0
0
0

@kirakira see I'm looking at this going "...what's the problem?". >,,>

1
0
0

@kirakira course, I don't think of JS objects as Fixed Classes

to me they're more like dictionaries where some of the properties are functions you can call; it makes perfect sense to be able to just add properties to objects like this

but yeah it's Not C++ that's for sure!

1
0
0

@IceWolf yeah see that was the mental model of js classes i didn't have

0
0
0

@kirakira i don’t understand what your problem with this is unless i’ve missed something obvious (although i agree that javascript is annoying as someone who has programmed a lot in it)

1
0
0

@tauon prior to the understanding i now have my expectation would have been "hey that field doesn't exist" like in other languages that call things classes

0
0
0