the amount of my life that has been lost to "javascript just lets you do shit without throwing any errors or warnings"
im becoming a c programmer after this at least c issues are exciting
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
@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~
@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")
}
}
@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)
@kirakira call this at the end of your constructor :3 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions
@kirakira side note: strict mode fixes the globalThis issue in constructor functions
@rowan i am learning so much :3
@kirakira see I'm looking at this going "...what's the problem?". >,,>
@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!
@IceWolf yeah see that was the mental model of js classes i didn't have
θΔ ⋐ & ∞
@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)
@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