Skip to content

Commit b55b10c

Browse files
committed
types: replace Function.name with an IE compatible alternative
1 parent eb4e888 commit b55b10c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/types.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ module.exports = function enforce(type, value) {
2626
}
2727

2828
default: {
29-
if (value.constructor.toString().match(/function (.*?)\(/)[1] === type.name) return
29+
if (getName(value.constructor) === getName(type)) return
3030
}
3131
}
3232

33-
throw new TypeError('Expected ' + (type.name || type) + ', got ' + value)
33+
throw new TypeError('Expected ' + (getName(type) || type) + ', got ' + value)
34+
}
35+
36+
function getName(fn) {
37+
// Why not fn.name: https://kangax.github.io/compat-table/es6/#function_name_property
38+
var match = fn.toString().match(/function (.*?)\(/)
39+
return match ? match[1] : null
3440
}

0 commit comments

Comments
 (0)