Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Placing a constant on prototype

Let's say i have the following class:

function Base() {};
Base.prototype.Const = 0;

and a derived function:

function Derived() {};

The Derived function has access to this.Const . Now my question is - I haven't seen any case where people define Consts on the prototype and i wonder why not? Is there any problem using this method? (it seems like a good practice to me since the const in not global and contained within the class and it's not on the this)

I'm not necessarily talking about a constant - but a variable that all the derived classes might want to use... like ID or something else

like image 731
Sandman Avatar asked Mar 17 '26 08:03

Sandman


1 Answers

You are using it right according to the JavaScript definitive guide Book

like image 193
Darshan Avatar answered Mar 19 '26 22:03

Darshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!