- Extends etc.
No Static Member Properties in class
You cannot declare properties directly in the class. You can only have it through class’s constructors, and properties created inside constructor is local to the object instances and not shared by all of them.
Above code will throw error “unexpected identifier”. There is a work around to create static property using the class prototype.
Now on the instances of Speaker class, you can access static property count.
Therefore, you are able to create a static property, but not without help of understanding of prototype. In my opinion class should have a way to create static property directly inside the class like a method or constructor.
Object instances does not copy definitions from class
To understand this problem, let us first revise Constructor Invocation Pattern and prototype chain. You have a function constructor Speaker.
Using new operator, you can create object instances,
In this approach, a and b object instances both have their own copy of hello method. Now if you add a hello method to Speaker.prototype, still a and b object instances will access their own copy of hello method. Consider below code: