You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionShape(x,y){this.x=x;this.y=y;}Shape.prototype.identify=function(){console.info('I am a shape');};Shape.prototype.move=function(x,y){this.x+=x;this.y+=y;console.info('Shape moved');};functionRectangle(x,y){// call super constructorShape.call(this,x,y);this.identify();}Rectangle.prototype=Object.create(Shape.prototype);varrect=newRectangle(5,10);rect.move(-1,2);console.log(rect.x,rect.y);
Via ES6 class
'use strict';classShape{constructor(x,y){this.x=x;this.y=y;}identify(){console.info('I am a shape');}move(x,y){this.x+=x;this.y+=y;console.log('Shape moved');}}classRectangleextendsShape{constructor(x,y){// call super constructorsuper(x,y);super.identify();}}varrect=newRectangle(5,10);rect.move(-1,2);console.log(rect.x,rect.y);