/typescript/

TypeScript part 4 (class)

2017-03-02 21:23:22

TypeScript

class Person {
    name: String
}
var michal = new Person();

michal.name = "Michał";
console.log(michal);

JavaScript

var Person = (function () {
    function Person() {
    }
    return Person;
}());
var michal = new Person();
michal.name = "Michał";
console.log(michal);

TypeScript

class Animal {
    name: string;

    constructor(name: string) {
        this.name = name;
    }
}

var dog = new Animal("Dog");
console.log(dog);

JavaScript

var Animal = (function () {
    function Animal(name) {
        this.name = name;
    }
    return Animal;
}());
var dog = new Animal("Dog");
console.log(dog);

TypeScript

class Building {
    private name: String = "no name";
    public setName(name: String): void {
        this.name = name;
    }
}

var shop = new Building();
shop.setName("Shop");

console.log(shop);

JavaScript

var Building = (function () {
    function Building() {
        this.name = "no name";
    }
    Building.prototype.setName = function (name) {
        this.name = name;
    };
    return Building;
}());
var shop = new Building();
shop.setName("Shop");
console.log(shop);