types: replace Function.name with an IE compatible alternative
This commit is contained in:
parent
eb4e8884d9
commit
b55b10c6b6
1 changed files with 8 additions and 2 deletions
10
src/types.js
10
src/types.js
|
@ -26,9 +26,15 @@ module.exports = function enforce(type, value) {
|
|||
}
|
||||
|
||||
default: {
|
||||
if (value.constructor.toString().match(/function (.*?)\(/)[1] === type.name) return
|
||||
if (getName(value.constructor) === getName(type)) return
|
||||
}
|
||||
}
|
||||
|
||||
throw new TypeError('Expected ' + (type.name || type) + ', got ' + value)
|
||||
throw new TypeError('Expected ' + (getName(type) || type) + ', got ' + value)
|
||||
}
|
||||
|
||||
function getName(fn) {
|
||||
// Why not fn.name: https://kangax.github.io/compat-table/es6/#function_name_property
|
||||
var match = fn.toString().match(/function (.*?)\(/)
|
||||
return match ? match[1] : null
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue