What lines of code need to be added in the Student constructor to properly inherit from Person?

Prepare for the Salesforce JavaScript Developer I Certification Exam. Utilize interactive quizzes, flashcards, and detailed explanations for each question. Boost your confidence and ace your exam effortlessly!

The correct choice involves using the super function call to invoke the constructor of the parent class (Person) and the Object.create() method to set up the prototype chain properly. This allows the Student class to inherit behaviors and properties from the Person class effectively.

By invoking super(fName, lName, age);, the constructor of Person is called with the appropriate parameters from the Student constructor, ensuring that any properties defined in Person are initialized correctly for instances of Student. This is an essential step for proper inheritance in JavaScript, especially when using class-based syntax.

The use of Student.prototype = Object.create(Person.prototype); establishes the prototype chain such that instances of Student will have access to methods defined on Person’s prototype, promoting effective inheritance of methods.

In contrast, the other options do not correctly establish the inheritance relationship or do not utilize the constructor in the proper way:

  • Some of the options attempt to use call or new inappropriately, which can lead to instances not being set up correctly or methods not being accessible.

  • Using super() without a proper constructor call to the parent class would also not achieve the necessary setup for inheritance.

Thus, the effective combination provided in the correct answer ensures proper

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy