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
Jamoliddin Fakhriddinov
Brent Farris you are the best! Thanks a lot!!!
Jochem Stoel
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
mounaim zaryouhi
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 !!";
}
}
SadakaTV
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
tjon 90
Thanks Brent! This is extremely helpful!
Abhijeet Kurle
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
ravi kanth
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
Orel Ohayon
Great video thanks! please upload more stuff ๐
iOSX Developer
Nice, thanks!