I am assigning the javaEnabled() function to a variable like this:

var je = navigator.javaEnabled;

Now when I try to invoke the function using je();, it throws an error in chrome that says

VM960:1 Uncaught TypeError: Illegal invocation(…)

In Firefox, the error is:

TypeError: 'javaEnabled' called on an object that does not implement interface Navigator.

Why does it fail like this?

1 Answers

1
zayjuc On Best Solutions

If you call something like obj.func(), func will be called with obj as its this value. Firefox complains about an incompatible this value. In your case it's either null or the global object (normally window), depending on context and if you use strict. javaEnabled needs the navigator object, just es Object.valueOf() needs Object.