You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cant call static owerriden methods, if i write Animal.run() this is code not use Cat.run owerriden method. i need write this.constructor.run() but it get compilation error.
classAnimal{staticrun(){alert('Animal run')}run(){this.constructor.run()// compile error// if i write Animal.run() this code not use Cat.run owerriden method}}classCatextendsAnimal{staticrun(){super.run()alert('Cat jump')}}letcat=newCat()cat.run()
solution
add keyword static for access to current static props, static will be alias for this.constructor in self methods, and alias for this in static methods
and code will be:
classAnimal{staticrun(){alert('Animal run')}run(){static.run()// compile to this.constructor.run()}}classCatextendsAnimal{staticrun(){super.run()alert('Cat jump')}}letcat=newCat()cat.run()// alert('Animal run') alert('Cat jump')
dangers
Static keyword to be used in the following standards and ES have different semantics
The text was updated successfully, but these errors were encountered:
Cant call static owerriden methods, if i write
Animal.run()
this is code not useCat.run
owerriden method. i need writethis.constructor.run()
but it get compilation error.solution
add keyword
static
for access to current static props,static
will be alias forthis.constructor
in self methods, and alias forthis
in static methodsand code will be:
dangers
Static keyword to be used in the following standards and ES have different semantics
The text was updated successfully, but these errors were encountered: