Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added undefined check #14

Merged
merged 1 commit into from Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser.js
Expand Up @@ -30,7 +30,7 @@ module.exports = function kindOf(val) {

// functions
if (type === 'function' || val instanceof Function) {
if (val.constructor.name.slice(0, 9) === 'Generator') {
if (typeof val.constructor.name !== 'undefined' && val.constructor.name.slice(0, 9) === 'Generator') {
return 'generatorfunction';
}
return 'function';
Expand Down Expand Up @@ -141,4 +141,4 @@ function isBuffer(val) {
}

},{}]},{},[1])(1)
});
});
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -29,7 +29,7 @@ module.exports = function kindOf(val) {

// functions
if (type === 'function' || val instanceof Function) {
if (val.constructor.name.slice(0, 9) === 'Generator') {
if (typeof val.constructor.name !== 'undefined' && val.constructor.name.slice(0, 9) === 'Generator') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when so much bytes is used, it's probably better to directly be checking of string.

So:

var name = (val.constructor && val.constructor.name) || ''
if (name && name.length && name.slice(0, 9) === 'Generator') {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially, i just meant that if (typeof val.constructor.name === 'string' && would be better, but later update my thought :D

return 'generatorfunction';
}
return 'function';
Expand Down