return named function in coffeescript

2019-08-17 06:03发布

问题:

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:

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.