Skip to content

Commit

Permalink
Workaround for missing function.name in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswilburn committed Sep 5, 2018
1 parent b9660b9 commit 912cfaf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion reflections/get-name/get-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function setName(obj, nameGetter) {
* @param {Object} obj The object to get from
* @return {String} The human-readable name of the object
*/
var anonymousID = 0;
function getName(obj) {
var type = typeof obj;
if(obj === null || (type !== "object" && type !== "function")) {
Expand All @@ -101,7 +102,11 @@ function getName(obj) {
}

if (type === "function") {
return obj.name; // + "()" // should we do this?
if (!obj.name) {
// IE doesn't support function.name natively
obj.name = "functionIE" + anonymousID++;
}
return obj.name;
}

if (obj.constructor && obj !== obj.constructor) {
Expand Down

0 comments on commit 912cfaf

Please sign in to comment.