In this video we go over how to inherit from classes (polymorphism) and we also go over how to override methods and call base methods.
Twitter ► https://twitter.com/ShieldCrush
Instagram ► https://www.instagram.com/BrentFarris
Original source
In this video we go over how to inherit from classes (polymorphism) and we also go over how to override methods and call base methods.
Twitter ► https://twitter.com/ShieldCrush
Instagram ► https://www.instagram.com/BrentFarris
Original source
9 responses to “JavaScript 6 03: Inheritance”
Brent Farris you are the best! Thanks a lot!!!
You shouldn't call super.constructor, you need to simply call super.
class Person {
constructor(name, age) {
super(name)
this.age = age
}
}
Also some advice for your coding style: stop using semi colons
Thanks Brent 🙂
Could you please explain why I'm getting this error :
VM656:3 Uncaught ReferenceError: this is not defined(…)SpecialCrazyDev @ VM656:3(anonymous function) @ VM822:1InjectedScript._evaluateOn @ VM103:145InjectedScript._evaluateAndWrap @ VM103:137InjectedScript.evaluate @ VM103:118
var specialDevvv = new SpecialCrazyDev("UI dev",20);
This is my code :
class CrazyDev{
constructor(job){
this.job = job;
}
toString(){
return "My job is " + this.job;
}
}
class SpecialCrazyDev extends CrazyDev{
constructor(job,age){
super.constructor(job);
this.age=age;
}
toString(){
return super.toString() + "I am a special crazy dev, I'm " + this.age+" years old !!";
}
}
class human {
contructor(name){
this.nm = name;
}
toString(){
return "Hello, my name is" + this.name + ".";
}
}
class enfant extends human{constructor(name, age){super.constructor(name); this.ag = age;} toString(){ return super.toString() + "im i human im enfant and my age is = "+ this.ag ; } }
undefined
var lolo = new enfant("mopi", 45);
ReferenceError: |this| used uninitialized in enfant class constructor
Thanks Brent! This is extremely helpful!
Got Error: |this| used uninitialized in Person class constructor
on line: super.constructor(name) but replaced with super(name)
got It.
Anyway Thnks a lot
Nice video, thanks!!
When I tried your example… i get |this| not initialized in class constructor error, for the creation of Person object.
It worked after changing it to super(name); instead of super.constructor(name).
Do you know what this might be… I'm sure that I have latest firefox nightly build
Great video thanks! please upload more stuff 🙂
Nice, thanks!