【发布时间】:2017-09-09 12:19:53
【问题描述】:
我有一个函数,我将另外 2 个函数作为参数传递,例如:
doSomething(func1,func2)
我需要的是在导出函数时在其他上下文中对 func1 进行原型设计。
例如我有 2 个不同的文件:
在第一个中,我导出了一个接收 2 个参数函数的函数:
module.exports = (func1, func2) => {
}
在第二个中,我像 doSomething(func1,func2) 一样传递了我之前所说的参数
我怎样才能在 module.exports 中对 toString 进行原型化,这样我才能得到这样的 function1 输出:
/* func1() */ func2()
我试过这样:
module.exports = (func1, func2) => {
func1.prototype.toString = function () {
const comment = `/* ${(_.toString(func1))} */ \n`;
return comment;
};
};
结果是没有 /* */ 的 func1 对此有任何帮助?
【问题讨论】:
-
the result was你是怎么得到这个结果的? -
是否要通过覆盖 toString 方法打印函数 1 代码?
-
我想通过原型函数 1 在函数 1 中打印函数 2
-
我认为“prototype”并不是指 JavaScript 中“prototype”通常所指的意思。
标签: javascript node.js ecmascript-6 lodash