return named function in coffeescript

2019-08-17 05:55发布

I have the following javascript:

Function.prototype.debounce = function (threshold, execAsap) {

    var func = this, timeout;

    return function debounced () {
       //body
    }
};

How can I return a named function like this in coffeescript?

1条回答
smile是对你的礼貌
2楼-- · 2019-08-17 06:42

You can't name functions in Coffeescript. The reason is given in the FAQ -- grep for "Is there any way to name functions, for reflection and recursion?" If you really need to embed a name, you could use backticks to embed raw Javascript.

查看更多
登录 后发表回答