Rectangle extending Shape - Javascript Object

Javascript examples for Object:prototype

Description

Rectangle extending Shape

Demo Code


function Shape() {
  this.x = 0//www  .  java 2 s .  c o  m
  this.y = 0
}

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

// Rectangle - ??(subclass)
function Rectangle() {
  Shape.call(this) // call super constructor.
}


Rectangle.prototype = Object.create(Shape.prototype)
// Rectangle.prototype.constructor = Rectangle
var rect = new Rectangle()

console.log(rect)

Related Tutorials