1

I copied most of the code from an MDN article on .create() with some slight modification:

// superclass
function Shape() {
    this.x = 0;
    this.y = 0;
};

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

// subclass
function Rectangle() {
    Shape.call(this); // call super constructor passing the current object
}

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

var rect = new Rectangle();

console.log( rect.move( 1, 1 ) );

Output:

Shape moved
undefined

Why is it getting undefined also?

Robert
  • 10,126
  • 19
  • 78
  • 130

1 Answers1

2

In JavaScript a function always returns undefined if no return value is specified. The move function does not return anything. So logging its output logs undefined.

Nick Bailey
  • 3,078
  • 2
  • 11
  • 13