fix(test): function.name is not available (IE11)

This commit is contained in:
Marc Laval
2015-05-21 11:30:56 +02:00
parent 1f20ef9787
commit 5103f080e9
2 changed files with 15 additions and 1 deletions

View File

@ -0,0 +1,13 @@
//function.name
/*! @source http://stackoverflow.com/questions/6903762/function-name-not-supported-in-ie*/
if (!(function f() {}).name) {
Object.defineProperty(Function.prototype, 'name', {
get: function() {
var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
// For better performance only parse once, and then cache the
// result through a new accessor for repeated access.
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}