Classes in ECMA Script 6
JavaScript is object based programming language where most of the work is done using functions. A function can act like a class or a function due to its prototypical nature. From the outset people felt a need for classes and used various framework which wraps class like functionality into the language. As has been a trend with all my tutorials first of all I will try to explain how to create classes with methods, properties etc. using prototype programming model and later we will jump to new way of programming classes which resembles most of the existing and old programming languages.
Let’s create a class in JavaScript with some variables like we do in other languages
<script type="text/javascript"> //A simple class with id property function myClass(id){ var id; function helloWorld(){ } } //Usage . As you can see we create object using new and pass any //required parameters into constructor var objMyClass = new myClass(1); console.log(objMyClass.id); console.log(objMyClass.helloWorld()); </script>