将自定义类型作为函数:用JavaScript中的另一个命名函数构造一个函数

问题描述

我正在尝试创建自己的自定义类型,这不仅仅是一个对象,而是一个函数

我试图获得以下结果,其中函数super1和super2由名称为Super的函数构造。

function super() {}         // fill in missing parts here...
const super1 = new super(); // fill in missing parts here...
const super2 = new super(); // fill in missing parts here...
console.log(super1,super1.constructor,super1.constructor === Super); // yields: [Function: super1] [Function: Super] true
console.log(super2,super2.constructor,super2.constructor === Super); // yields: [Function: super2] [Function: Super] true

我基本上希望能够检测给定功能是否由特定的其他功能构造,在上面的示例中,功能super1和super2是否由功能Super构造。

我正在尝试模仿基本JavaScript类型的类似行为:

const date = new Date();
console.log(date,date.constructor,date.constructor === Date); // yields: [Function: date] [Function: Date] true

任何想法...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)