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

TypeError: Function.prototype.toString is not generic #2

Closed
Xotic750 opened this issue Nov 30, 2015 · 3 comments
Closed

TypeError: Function.prototype.toString is not generic #2

Xotic750 opened this issue Nov 30, 2015 · 3 comments
Assignees

Comments

@Xotic750
Copy link

I was performing some tests on a module which was converted to use isCallable instead of typeof and I came across this error.

TypeError: Function.prototype.toString is not generic

Following through the test code, this is what causes the error to be thrown

function NameBuilder(first, last) {
    this.first = first;
    this.last = last;
}

NameBuilder.prototype = Object;

console.log(isCallable(new NameBuilder('John', 'Smith')));

http://jsfiddle.net/Xotic750/58hjhtsk/1/

Anyway, I did not expect isCallable to throw an error but return false. Is this fixable?

@ljharb
Copy link
Member

ljharb commented Nov 30, 2015

Interesting - this is caused specifically because the value isn't a function, but it has a function in its [[Prototype]]. This is definitely fixable, I'm not sure how just yet.

@ljharb ljharb self-assigned this Nov 30, 2015
@ljharb
Copy link
Member

ljharb commented Nov 30, 2015

(aside: how do you even find these? why would anyone set a function as a .prototype on a constructor?? :-p)

@ljharb ljharb closed this as completed in 624beaf Nov 30, 2015
@Xotic750
Copy link
Author

This test originates from commonjs-assert, the browser version of nodes assert, that is used by browserify. As I was working on fixing some issues that I was having with deepEqual and assert (for my own modules as not every developer is as welcoming/diligent as you), and so these original tests were included to make sure nothing else was broken. It's not always just me making up weird tests. :P

And as an amateur, I'm a bit like a child as I play with things (not necessarily correctly) until I break them. Javascript is a kind of hobby for me since I suffered a stroke and nobody wants to employ me any more. So I have to do something with my time so as not to go crazy, and you never know one day someone may employ me to do some Javascript from home (and I can actually earn some money again and feel a bit better about the cards that life deals one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants