Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
This kind of encapsulation is a great idea, but I strongly suggest getting an IDE setup that can tell you what type this has at the time you use it. I think it's one of the best reasons to use Typescript.
it's pretty easy to accidentally miss that only name and sendName use the dog's name. both fullName and sayName will use "bob"
As you say, the reasons for this are a little out of scope, but getting a good IDE setup will catch this bug just as well as knowing why it happens, and is a must if you're going to use this in JS imo.
VSCode with Typescript (or just a good JS type inference setup) will put nice big red squigglies under the dodgy bits.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This kind of encapsulation is a great idea, but I strongly suggest getting an IDE setup that can tell you what type
this
has at the time you use it. I think it's one of the best reasons to use Typescript.For example, in
it's pretty easy to accidentally miss that only
name
andsendName
use the dog's name. bothfullName
andsayName
will use "bob"As you say, the reasons for this are a little out of scope, but getting a good IDE setup will catch this bug just as well as knowing why it happens, and is a must if you're going to use
this
in JS imo.VSCode with Typescript (or just a good JS type inference setup) will put nice big red squigglies under the dodgy bits.