TypeScript
class Car {
   speed: string;
   constructor(speed: string) {
        this.speed = speed;
    }
}

let car1 = new Car('40');
let car2 = new Car('60');

alert("Car1 Speed: " + car1.speed);
alert("Car2 Speed: " + car2.speed);

One thing we should note that for inheritance works correctly, the Properties should be set in the prototype property of the class (function).

function Car(speed) {
    alert("Class CAR Instantiated");
    this.speed = speed;
}
Car.prototype.speed= 'Car Speed';

var car1 = new Car(40);
var car2 = new Car(60);

alert("Car1 Speed: " + car1.speed);
alert("Car2 Speed: " + car2.speed);

results matching ""

    No results matching ""