Fehlermeldung
TypeError: invalid 'instanceof' operand "x" (Firefox) TypeError: "x" is not a function (Firefox) TypeError: Right-hand side of 'instanceof' is not an object (Chrome) TypeError: Right-hand side of 'instanceof' is not callable (Chrome)
Fehlertyp
Was ist falsch gelaufen?
Der instanceof
Operator erwartet als rechten Operand einen Konstruktorobjekt, z. B. ein Objekt, welches eine prototype
Eigenschaft hat und aufrufbar ist.
Beispiele
"test" instanceof ""; // TypeError: invalid 'instanceof' operand ""
42 instanceof 0; // TypeError: invalid 'instanceof' operand 0
function Foo() {}
var f = Foo(); // Foo() is called and returns undefined
var x = new Foo();
x instanceof f; // TypeError: invalid 'instanceof' operand f
x instanceof x; // TypeError: x is not a function
Um diesen Fehler zu beheben, kann entweder der instanceof
Operator durch einen typeof
Operator ersetzt werden, oder man muss sicher stellen, dass ein Funktionsname statt einem Resultat seines Aufrufes benutzt werden.
typeof "test" == "string"; // true
typeof 42 == "number" // true
function Foo() {}
var f = Foo; // Do not call Foo.
var x = new Foo();
x instanceof f; // true
x instanceof Foo; // true