_new

模拟实现`new`操作符

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function/_new

说明

模拟实现new 操作符

用法

index.ts
import utilityFunction from "./ddzy/utility/function";
function Person() {
}
Person.prototype = {
say() {
console.log('saying...');
},
};
const p1 = utilityFunction._new(Person);
console.log(p1);
function Person2(name: string) {
this.name = name;
}
Person2.prototype = {
say() {
return this.name;
},
};
const p2 = utilityFunction._new(Person2, 'duan');
console.log(p2);
const p3 = new Person();
console.log(p3);