top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Class in Javascript (ECMASCRIPT 6)?

0 votes
103 views

Class in Javascript

     JavaScript classes introduced in ECMAScript 6 are syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript. ​

One way to define a class is using a class declaration. To declare a class, you use the class keyword with the name of the class

Example :

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    toString() {
        return `(${this.x}, ${this.y})`;
    }
}

 

For Calling its same like ES5  

var p = new Point(25, 8);

 Classes support prototype-based inheritance, constructors, super calls, instance and static methods.

Video for ES6 Classes

 For More Visit Official Site : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes

posted Sep 29, 2016 by Parampreet Kaur

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

ES(ECMASCRIPT) 6 provides two new ways of declaring variables: let and const, which mostly replace the ES5 way of declaring variables, var.

LET

let works similarly to var, but the variable it declares is block-scoped, it only exists within the current block. var is function-scoped.


function order(x, y) {
    if (x > y) { // (A)
        let tmp = x;
        x = y;
        y = tmp;
    }
    console.log(tmp===x); // ReferenceError: tmp is not defined
    return [x, y];
}

CONST
const works like let, but the variable you declare must be immediately initialized, with a value that can’t be changed afterwards.

const allows you to declare a single assignment variable lexically bound. 


const foo;
    // SyntaxError: missing = in const declaration

const bar = 123;
bar = 456;
    // TypeError: `bar` is read-only

VAR
With const and let, there is no more space for var anymore.

 

Video Tutorial

https://www.youtube.com/watch?v=zfCATpShE5g

READ MORE
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...