Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Three ways to define class in JavaScript

In object oriented programming, class is the template of object, it defines the properties and methods of a group of objects. Unfortunately, JavaScript doesn't support class, but we can have some workarounds to simulate class.1. Constructor functionThis is the classical approach, it is also the approach mentioned in many text books. It uses the constructor function to simulate class and it uses the keyword this to represent the object internally.function Cat() {  this.name = "Kelly";}when creating the instance, use the new keyword.var cat1=new Cat();alert(cat1.name); //KellyThe p...

11,803 0       JAVASCRIPT METHOD CLASS INHERITANCE PRIVATE