Поменять версию можно в
tsconfig.json
es6 если в файле tsconfig.json версия "target" : "es6" то после компиляции полчается такой javascript файл:
json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6"],
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
JavaScript
// describe the class
class Book {
// class constructor with parameters
constructor(newName, newPrice) {
this.name = newName;
this.price = newPrice;
}
// class method
showBook() {
console.log("Book name " + this.name + " , price " + this.price);
}
}
// create a class object Book
var book1 = new Book("Властелин колец", 120); // the constructor is called constructor(newName: string, newPrice: number)
book1.showBook(); // call the method showBook
// create a class object Book
var book2 = new Book("Аладин", 230); // the constructor is called constructor(newName: string, newPrice: number)
book2.showBook(); // call the method showBook
// ждем чтобы окно не закрылось. Окно закроется если пользователь нажмет на [x]
process.stdin.resume();
es5 когда я ставлю в tsconfig.json версию "target" : "es5" то после компиляции полчается такой javascript файл:
json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es6"],
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
JavaScript
// describe the class
var Book = /** @class */ (function () {
// class constructor with parameters
function Book(newName, newPrice) {
this.name = newName;
this.price = newPrice;
}
// class method
Book.prototype.showBook = function () {
console.log("Book name " + this.name + " , price " + this.price);
};
return Book;
}());
// create a class object Book
var book1 = new Book("Властелин колец", 120); // the constructor is called constructor(newName: string, newPrice: number)
book1.showBook(); // call the method showBook
// create a class object Book
var book2 = new Book("Аладин", 230); // the constructor is called constructor(newName: string, newPrice: number)
book2.showBook(); // call the method showBook
// ждем чтобы окно не закрылось. Окно закроется если пользователь нажмет на [x]
process.stdin.resume();