I am getting slightly confused about all this…
Chrome and Firefox both tell me different things, and I couldn’t find any part in the spec that mentioned it, but:
in Chrome:
Object instanceof Function // true
Function instanceof Object // true
Worker instanceof Object // true
Worker instanceof Function // false <- WTF???
in FireFox:
Object instanceof Function // true
Function instanceof Object // true
Worker instanceof Object // false
Worker instanceof Function // false
of course, an initialised new Worker() is both a Worker and an Object, but why is the Worker constructor not a function?
Worker IS of type function. You can check that using the
typeofoperator. However, it does not inherit the prototype of the Function constructor, hence it is not aninstanceofFunction.Here’s a more practical example:
From MDN:
Worker does not inherit the Function constructor’s prototype, hence it is not an instance of Function.
Here’s an example using the
typeofoperator to check if the user’s browser supports the Web Workers API:Fiddle