TypeScript

interface ClockInterface {
    currentTime: Date;
}

class Clock implements ClockInterface {
    currentTime: Date;
    constructor(private h: number.private m: number) { this.currentTime = new Date();
    }
}
Copy the code

JavaScript

var Clock = / * *@class * / (function () {
    function Clock(h, m) {
        this.h = h;
        this.m = m;
        this.currentTime = new Date(a); }returnClock; } ());Copy the code

The parameters defined in the constructor automatically become properties of the JavaScript function.

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: