Prototype-based Inheritance in JavaScript using the 'create' Method

function fruits() { // Defines a constructor function named "fruits" this.name = 'fruit'; // Creates a property "name" and assigns it the value 'fruit' within the "fruits" constructor this.season = 'Winter'; // Creates a property "season" and assigns it the value 'Winter' within the "fruits" constructor } function apple() { // Defines another constructor function named "apple" fruits.call(this); // Calls the "fruits" constructor within the context of the current object (this), effectively setting its properties } apple.prototype = Object.create(fruits.prototype); // Creates a new object that inherits from the prototype of "fruits" and sets it as the prototype of "apple" const app = new apple(); // Creates a new instance of the "apple" constructor and assigns it to the variable "app" console.log(app.name, app.season); // Outputs the value of the "name" and "season" properties of the "app" object, which are 'fruit' and 'Winter' respectively console.log(app.season); // Outputs the value of the "season" property of the "app" object again, which is 'Winter'

Output: