【发布时间】:2016-12-26 11:04:48
【问题描述】:
interface Function {
next(next: Function): Function;
prev(prev: Function): Function;
}
Function.prototype.next = function(next) {
const prev = this;
return function() {
return next.call(this, prev.apply(this, arguments));
};
};
Function.prototype.prev = function(prev) {
const next = this;
return function() {
return next.call(this, prev.apply(this, arguments));
};
};
const f1 = function() { console.log("f1"); };
const f2 = () => console.log("f2");
const f3 = new Function("console.log('f3');");
f1.next(f2).next(f3)();
我想做坏事,将 TypeScript 编译中的 Function 原型扩展为 ES6。虽然此代码在 TypeScript Playground 中运行良好,但在 tsc 1.8.10 中失败(属性<<name>> 不存在于类型'Function'),因为它无法与lib.es6.d.ts 中的函数定义合并。
任何想法如何正确地做到这一点?
【问题讨论】:
标签: javascript function typescript ecmascript-6 prototype