Javascript

Classical inheritance in JS using Object.create()

function Shape() { this.x = 0; this.y = 0; } Shape.prototype.move = function(x, y) { this.x += x; this.y += y; console.log(“x : ” + this.x); //x: 1 console.log(“y : ” + this.y); //y: 1 }; function Rectangle() { Shape.call(this); } Rectangle.prototype = Object.create(Shape.prototype); Rectangle.prototype.constructor = Rectangle; var rect = new Rectangle(); console.log(rect instanceof Rectangle);… Continue reading Classical inheritance in JS using Object.create()