This JavaScript exception called on incompatible target (or object)” occurs if a function (on a given object), is called with a ‘this’ corresponding to a different type other than the type expected by the function.
Message:
TypeError: 'this' is not a Set object (EdgE) TypeError: Function.prototype.toString called on incompatible object (Firefox) TypeError: Function.prototype.bind called on incompatible target (Firefox) TypeError: Method Set.prototype.add called on incompatible receiver undefined (Chrome) TypeError: Bind must be called on a function (Chrome)
Error Type:
TypeError
Cause of Error: Somewhere in function calls, function (on a given object), is called with a ‘this’ not corresponding to the type expected by the function.
Example 1: In this example, the GFG_Set.add is a function, but GFG_Set is not captured as ‘this’.
HTML
< script > var GFG_Set = new Set; ['Geek', 'GFG'].forEach(GFG_Set.add); </ script > |
Output(in console):
TypeError: 'this' is not a Set object
Example 2: In this example, GFG_Fun.bind is a function, but GFG_Fun is not captured as ‘this’.
HTML
< script > var GFG_Fun = function () { console.log(this); }; ['Geek', 'GFG'].forEach(GFG_Fun.bind); </ script > |
Output(in console):
TypeError: 'this' is not a Set object