1

What is difference if any between "instantiating" the JavaScript "class" with or without using parenthesis?

function Animal(name) {
     this.name = name;
}

Animal.prototype.sayName = function() {
     console.log(this.name);
};

function Dog(name) {
     Animal.call(this, name);
}

Dog.prototype = new Animal(null);
Dog.prototype.bark = function() {
     console.log("Woof!");
};

var d = new Dog

or

var d = new Dog()
exebook
  • 32,014
  • 33
  • 141
  • 226

1 Answers1

0

This question has already been asked here

There is no difference between them, as long as the constructor function takes no parameter. That is: calling new Dog (with no parentheses) is like calling new Dog() with no arguments.

Community
  • 1
  • 1
Buch
  • 92
  • 3