function.name not supported in IE.

前端 未结 5 992
面向向阳花
面向向阳花 2020-11-29 10:01

Lately I\'ve become a huge fan of the function.name property.

For example, I\'ve written a function for extending prototypes.

It works in the w

5条回答
  •  清酒与你
    2020-11-29 10:52

    You might be able to parse the function name from calling function.toString [docs]. function.name is not a standard property.

    var name = func.toString().match(/^function\s*([^\s(]+)/)[1];
    

    As the comments also say, this is not necessarily a reliable way. Imo passing an object would be easier to read and you could pass several methods at once:

    Array.give({
        forEach: function() { ... },
        somethingElse: function() {...}
    });
    

提交回复
热议问题