Skip to content

Wolf-Team/extends

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

extends

How use

IMPORT("extends", "__extends");

function ParentClass(){}
ParentClass.prototype.b = 1;

__extends(ChildClass, ParentClass);
function ChildClass(){
    ParentClass.apply(this, arguments);
}

Example

There is a class written in TypeScript

class ParentClass {
    constructor() {
        alert("Create!");
    }

    public method(a: number | string) {
        alert("method: " + a);
    }
}

Inheriting from this class in TypeScript looks like this

class ChildClass extends ParentClass{
    public method(){
        super.method("Child!");
    }
}

How to write this in JavaScript using __extends

IMPORT("extends", "__extends");

function ChildClass(){
    ParentClass.apply(this, arguments);
}
__extends(ChildClass, ParentClass);
ChildClass.prototype.method = function() {
    ParentClass.prototype.method.call(this, "Child!");
}