I am so confused with inheritance

please help me! Don’t know why this wouldn’t work:

class Parent {
            render() {
                console.log('parent')
            }
        }

        class Child extends Parent {
            static cRender() {
                this.render()
            }
        }

        Child.cRender() //  error msg: this.render is not a function
    at Function.cRender

I thought i could access the method in the Parent class like that.
i did some trial and error:

class Parent {
            render() {
                console.log('parent')
            }
        }

        class Child extends Parent {
             cRender() {
                this.render()
            }
        }
        
        const child = new Child() 
        child.cRender() // works. But i don't properly understand why the first wouldn't work
 class Parent {
            static render() {
                console.log('parent')
            }
        }

        class Child extends Parent {
            static cRender() {
                this.render()
            }
        }
        
        Child.cRender() // this also works with static methods in both - i don't really get

In static methods this refers to class itself while in prototype methods this refers to instance of the class. So when you’re invoking this.render() in the first example it looks for static method render either on Child or Parent

1 Like

Thank you so much!!!