1.

How Can You Allow Classes Defined In A Module To Be Accessible Outside Of The Module?

Answer»

Classed define in a module are available WITHIN the module. Outside the module, you can’t access them.

module Vehicle {
class Car {
CONSTRUCTOR (
public make: string, 
public model: string) { }
}
var audiCar = NEW Car("Audi", "Q7");
}
// This won't work
var fordCar = Vehicle.Car("Ford", "Figo");

As per above code, fordCar variable will give us compile time error. To make classes ACCESSIBLE outside module, use export keyword for classes.

module Vehicle {
export class Car {
constructor (
public make: string, 
public model: string) { }
}
var audiCar = new Car("Audi", "Q7");
}
// This works now
var fordCar = Vehicle.Car("Ford", "Figo");

Classed define in a module are available within the module. Outside the module, you can’t access them.

module Vehicle {
class Car {
constructor (
public make: string, 
public model: string) { }
}
var audiCar = new Car("Audi", "Q7");
}
// This won't work
var fordCar = Vehicle.Car("Ford", "Figo");

As per above code, fordCar variable will give us compile time error. To make classes accessible outside module, use export keyword for classes.

module Vehicle {
export class Car {
constructor (
public make: string, 
public model: string) { }
}
var audiCar = new Car("Audi", "Q7");
}
// This works now
var fordCar = Vehicle.Car("Ford", "Figo");



Discussion

No Comment Found