jeandremelaria
3/28/2018 - 11:37 AM

Javascript es6/es2015

class and methods


/* CLASS */

class User {
	
}

/* FUNCTIONS / METHOD */
register () {
	console.log('User Registered...');
}


/* CLASS AND METHOD EXAMPLES */
class User {
    constructor(username, email, password) {
        this.username = username;
        this.email = email;
        this.password = password;
    }

    static countUsers() {
        console.log('There are 50 users');
    }

    register() {
        console.log(this.username + ' is Registered')
    }
}

let John = new User('John', 'John@hotmail.com', '1234'); // Creating new user John

John.register(); // Calling register method

User.countUsers(); // Calling countUsers method

John.register(); // calling method register