Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 895 Bytes

README.md

File metadata and controls

55 lines (42 loc) · 895 Bytes

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!");
}