DEV Community

Discussion on: OOP JAVASCRIPT PROBLEM !!!

Collapse
 
hoangtrinh profile image
Hoàng devtrai

well if you really want the constructor to only receive string, you can just throw an error if the parameter is not a string with "typeof"

if(typeof name !== 'string') throw Error('Only string is allowed you mother fucker');

but nowadays devs use Typescript instead, they can just config the compiler to fail the build if it's violate TS rules, like passing number into string

Collapse
 
adev03 profile image
Ayoub

thanks

Collapse
 
codingjlu profile image
codingjlu

I guess I'm not a dev then. Hmm?