Skip to content

Commit

Permalink
Merge pull request #146 from canjs/ie11-compat
Browse files Browse the repository at this point in the history
Workaround for missing function.name in IE
  • Loading branch information
cherifGsoul authored Oct 16, 2018
2 parents 943013f + 33ec41c commit e431d12
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 (!("name" in obj)) {
// 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 e431d12

Please sign in to comment.