Skip to content

Instantly share code, notes, and snippets.

@adyontech
Created February 20, 2020 17:26
Show Gist options
  • Save adyontech/6ca87dcf376ddda60afc22c9442d0fc5 to your computer and use it in GitHub Desktop.
Save adyontech/6ca87dcf376ddda60afc22c9442d0fc5 to your computer and use it in GitHub Desktop.
Classical inheritance with function
function Shape(){
      this.x = 0;
      this.y = 0;
  }


Shape.prototype.move = function (x, y){
  this.x += x;
  this.y += y;
  console.info('Shape moved.');
}

function Rectangle(){
  Shape.call(this);
}

Rectangle.prototype = Object.create(Shape.prototype);

Rectangle.prototype.contructor = Rectangle;

var rect = new Rectangle();

rect.move(1, 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment