Skip to main content

Posts

Showing posts with the label class

The Class in Javascript - ES 6

In Javascript ES 5,we didn't have class as other languages like Java or C#. However, we use to create a function, in such a way, that it will act as a class. e.g.
function Person(name,age) {        this.name = name;        this.age = age;  }  var person1 = new Person("Alex", 27); console.log(person1); Person {name: "Alex", age: 27}age: 27name: "Alex"__proto__: Object We already had prototype-based inheritance for class, provided by functions, in javascript. The JavaScript classes, introduced in ES 6, are primarily syntactical sugar over this. The class syntax does not introduce a new object-oriented inheritance model to JavaScript. That means, JavaScript class is a type of function. Classes are declared with the class keyword. We usually write class name in Pascal-caseing. Like function, classes can be written in two ways, class declaration and class expression.
Class Declaration  We use function expression syntax to initialize a function and class expressio…