Question regarding the Class Statics in JS


Question regarding the Class Statics in JS

I am reading a book "JavaScript object programming". So far I get what author is saying about object programming. Now I am on page where he said:

Creating Class Statics

Class-wide data (data that applies to every instance) can be attached as a property of theconstructor, as Listing 1-10 shows.

Dog.diet = "carnivore"; // not prototype alert(lassie.diet); // undefined Dog.prototype.diet = "carnivore"; alert(lassie.diet); // carnivore 

I don't get what he meant by "data that applies to every instance". Because when I add diet property to Dog, how the instances of Dog will get the access to the property?

Submitted August 13, 2017 at 01:14AM by arup_r
via reddit http://ift.tt/2wSXwsi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s