0

I am trying to follow the MDN article Introduction to Object-Oriented JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

In there it defines a constructor as:

var Person = function(firstName) {
  this.firstName = firstName;
}

and

function Student(firstName, subject) {
  // Call the parent constructor, making sure (using Function#call)
  // that "this" is set correctly during the call
  Person.call(this, firstName);

  // Initialize our Student-specific properties
  this.subject = subject;
}

Why is the Student constructor not defined as:

var Student = function(firstName, subject) {
  // Call the parent constructor, making sure (using Function#call)
  // that "this" is set correctly during the call
  Person.call(this, firstName);

  // Initialize our Student-specific properties
  this.subject = subject;
}
Allan Chau
  • 693
  • 1
  • 5
  • 15
  • I'm struggled to see the difference. – zerkms Apr 08 '16 at 04:31
  • The difference is one is using a function declaration whereas the other is using a function expression. If I understand correctly, the function expression is hoisted differently. In this case though I could probably use either? – Allan Chau Apr 08 '16 at 04:58

0 Answers0