console.log("Hello world! - typescript.jsrun.net")
function customNew<T>(constructor_: Function, ...args: any[]): T {
const obj = Object.create(constructor_.prototype)
constructor_.apply(obj, args)
return obj
}
class Foo {
name: string
city: string = '北京'
n: number
constructor(name: string, n: number ) {
this.name = name
this.n = n
}
getName() {
return this.name
}
}
function foo_(name: string, n: number) {
this.name = name
this.n = n
}
foo_.prototype.getName = function () {
return this.name
}
console.info(customNew(foo_, '数月', 10))