Monthly Archives: May 2020

Why ES6 class in Javascript: methods are stored in prototype, but fields are in instance

Let’s create Javascript class and object with this new class: class Rectangle { constructor(height, width) { this.height = height; this.width = width; } getHeight() { return this.height } state = ‘some state’ } const rect = new Rectangle(1, 2); rect._proto_.state undefined rect._proto_.getHeight ƒ getHeight() { return this.height } rect.state ‘some state’ As you see, methods […]