extended class call method from super in javascript

class Rectangle {
  constructor(height, width) {
    this.name = 'Rectangle';
    this.height = height;
    this.width = width;
  }
  sayName() {
    console.log('Hi, I am a ', this.name + '.');
  }
  get area() {
    return this.height * this.width;
  }
  set area(value) {
    this._area = value;
  }
}

class Square extends Rectangle {
  constructor(length) {
    this.height; // ReferenceError, super needs to be called first!

    // Here, it calls the parent class's constructor with lengths
    // provided for the Rectangle's width and height
    super(length, length);

    // Note: In derived classes, super() must be called before you
    // can use 'this'. Leaving this out will cause a reference error.
    this.name = 'Square';
  }
}

4
10
Awgiedawgie 440215 points

                                    // this is how we call method from a super class(i.e MAIN CLASS) to extended class
class Person {
 constructor(name, age) {
  this.name = name;
  this.age = age;
 }
greet() {
  console.log(`Hi, all my name is ${this.name}`);
 }
}

class Employee extends Person {
 constructor(name, age, employer) {
  super(name, age);  // NOTE : super must call before accessing (this)
  this.employer = employer;
 }

 greeting() {
  super.greet();  // this is how we call
  console.log(`I'm working at ${this.employer}`);
 }
}

let Steve = new Employee('Xman', 25 , 'Skynet');
Steve;
Steve.greeting(); // check by consoling MATE

4 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
super(this) in javascript purpose of super in javascript javjascript super() super in javascrypt understanding super js how to use super in js superagent javascript super keyword used for javascript how to write superscript in java what is the use of super keyword in javascript how to use superscript in javascript javascript super(); why does super function work javascript meaning of super in javascript what is super used for in javascript use of super keyword in js js super why we are super method in js super in javascript w3schools what does the super keyword do js super method in js when is super used in js what is super() javascript javascritp super super keyword in js brief super use javascript use super in javascript javascript superscript superscript in javascript Superscript in Java how to make superscript in java the super function javascript javascirpt super super() javscript how get methods from extended class javascript super this javascript super en javascript what is the use of super in javascript super() funtion in javascript super meaning js use superscript in javascript super syntax js super method jaavscript what is the use of super() in js super() in javascript use? javascript _super super() javascript looks for supers() javascript what super does?js what does super keyword do in javascript js function super call super in extended class javascript javascript super() w3s super of javascript super keyword in js when to use super in javascript what is super._ in javascript why we use super keyword in javascript what does super do javascript super. or this. js uses of super in java javascript superscript javascript super keyword in javasccirpt super(); javascript what is super keyword in javascript o superscript how to superscript javascript super return java Superscript javscript super keyword what is a super javascript js what is super java script super js superscript javascript super for function how to call method from extended class define super in javascript super definition programming javascript javascript superscirpt javascript methods super what can you use the keyword super for in javascript how to do a superscript super() keyword js what does javascript super do using super() in javascript how to use super() in js super javascript definition js pass this to super ES6 classes no longer need constructor super super method depreciation on js how to use super constructor in derived class javascript extends an d super key word in js super angular constructor super in js explained construct super in js super equivalent in js super methods in javascript superscript js class super constructor class super javscript is not a function super javascript extends super javascript suiper.js how to call parent methods with super keyword in javascript call methods in superclass javascript this to superclass javascript give this to superclass javascritp call super class method javascript how to get a reference of a super object in js how to get a super reference of a child object in js calling super javascript super() in js function what is use of super keyword in js super keyword example in javascript class's super method javascript js super() angular super super extend class javascript what is super in javascript class inline assignment of parent class javascript extends syntax super constructor js extends syntax supper constructor js classes javascript constructor super what is super() in javascript construcor super(parameter); js call super class method js javascript prototype inheritance call super method javascript prototype super javascript es6 class call parent method using super method es6 role of super in js super-set of javascript javascript this super javascript overwrite super super javascript constructor javascript super alternative in function constructor javascript call parent constructor method inheritance and super javascript js clas super undefined call super javascript super(...arguments); javascript class super constructor javascript call super constructor js super class JavaScript use of super why should i call super() before using this in js constructor super js example how to get a classes super javascript javascript patrent class constructor this vs super js JS call super's super method js call parent function what is super in js js construct super js super database super function in javascript parent constructor in javascript super class js es6 call inherited class constructor js this super es parent method super call es6 call parent method super js super.method.call super() keyword javascript set paretn construcotr js call super js javascript call super method before super constructor super class in javascript es6 class extends access parent class super js javascript class super methods super class javacript create a class with constructor and super in javascript super extends subclass javascript js class constructor super class.constructor.super class call parent function javascript how to use super at classes javascript javascript super // javascript super command javascript class call super constructor super function class js javascript class constructor super what is super javascript why to use super keyword in javascript js class constructor super method javascript class extends super super() angular es6 classes super method ES6 super javascript set default property after super constructor super syntax javascript can a Constructor methods cannot use the keyword super to call the class parent. js pass super class constructor js constructor super explained javascript super keyword js super or sub classes js call superclass override super function in javascript super with named properties is super a function js class es6 with super extended class call method from super in javascript super() in constructor js javcascript prototype function call super superscript in rpt what is super in javascript class Super(); super() in js es6 class extends super es6 reference child constructor javascript super( super javascriot constructor vs super classes javascript super js syntax calling a function with super super method in js classes super method inside constructor javascript js this in super call javascript super. when to use super constructor in javescript seven.js:5 Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor at new Seven (seven.js:5) what does super do in javascript super javascirpt js classes super constructor super why do super come after constructor functions super(); in js must call super constructor before using 'this' .super_.call() super method in javascript javascrtitp prototype super super es6 class supe rin javascript class javascript calling super method on class super in class javascript constructor and supper how to use super in class javascript javascript webcompiler parent constructor javascript constructor super es5 whats super in javascript constructor super javascript MDN JavaScript ES6 super why do we need super() in an extended class super in javascir[t js super method what does super() do in javascript what is a super class in javascript does it mandatory to use parent consturctor in javascript In ES6, which keyword allows you to call into a super class method from a derived class method of the same name? super class javascript javascirpt super() error class super javascript class super js super variables not defined after super call super function javascript extending classes javascript super super operator es6 get properties of super class in javascript value of this before super constructor javascript js class super js super constructor class with constructor square js super inheritance javascript use of super keyword in javascript super constructot in js es6 class javascript get all accessible from super class using super in javascript calling super in a javascript class js call super constructor how to use super constructor in javascript parent constructor javascript oop super javascript super method in es6 class js superclass javascript super function in javascript wont work before this super constructor in js objVarExpr super es6 super() javascript call super method javascript es6 class super super on a non extented class javascript super() javascript super function super() what does super does not js what is super() in javascript super javacript parent constructor example in js extend super javascript wha are javascript calsses sper constructor function access super javascript super class in js this super is not a function javascript set the constructo by calling super() call superclass function javascript javascript es6 call method from parent class js super keyword constructor super node.js Why do we need super () in an extended class? why do we need super() in an extended class? call a sub construtor in javascript super in javascript class super in js classes and why it is important super class in javscript child class access super method javascript add super to class js super keyword in javascript super es6 purpose of super in constructor javascript call super method javascript inheritance super javascript class extends super super keyword js class super javascript javascript constructor super is it necessary to call constructor of parent class in javascript javascript class super not using only methods javascript must call super constructor javascript super() keywork javascript classes super js class extends super what's super.init in js classes what's super in js classes class super() supetr javascript super keyword javascript javascript super class angular js super angular js super.syncData return super() in javascript super in node js super in js super.this js pass parameters from super keyword js super pass parameters js super() js js this vs super javascript class parent constructor function constructor super js function super js super constructor javascript js super what is super() in js javascript super method super in es6 js super in js classes how to do a super in javascript javascript how to run constructor of super class javascript super java script constructor super javascript super call javascript super constructor super node js javascript super() method java script class super super method javascript super classes javascript javascript super example super in javascript js call super method how to use clas to get the parent in javascript super super explained node super() node javascript super in constructor explained super and extends javascript super js how to use super in javascript super() javascript super javascript super javscript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source