Javascript Aside: ES6 Classes

Big word

Syntactic sugar: A feature that only changes how you type something, but nothing changes under the hood

It's important to understand what is happening under the hood, so we don't make decisions based on flawed assumptions.

The code

'use strict';

class Person {
    constructor(firstname, lastname) {
        this.firstname = firstname;
        this.lastname = lastname;
    }

    greet() {
        console.log('Hello, ' + this.firstname + ' ' + this.lastname);
    }
}

var john = new Person('John', 'Doe');
john.greet();

var jane = new Person('Jane', 'Doe');
jane.greet();

console.log(john.__proto__);
console.log(jane.__proto__);
console.log(john.__proto__ === jane.__proto__);

results matching ""

    No results matching ""