Closed as not planned
Closed as not planned
Description
🔍 Search Terms
class A{
// Disallow external instantiation
private constructor() {
}
}
After compilation
var A = /** @class */ (function () {
function A() {
}
return A;
}());
var A = /** @class */ (function () {
function A() {
// To prohibit external instantiation, the following method is more friendly
// This is added manually, can it be automatically generated?😊😊😊
// This is more in line with the characteristics of `private constructor`
if (new.target === A) { // es6
throw Error('Prohibit instantiation')
}
if (this.constructor === A) { // old version
throw new Error("Prohibit instantiation");
}
}
return A;
}());