Object.prototype.__noSuchMethod__

ObsoleteThis feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The __noSuchMethod__ property used to reference a function to be executed when a non-existent method is called on an object, but this function is no longer available.

While __noSuchMethod__ has been dropped, the ECMAScript 2015 specification has the Proxy object, with which you can achieve the below (and more).

Syntax

obj.__noSuchMethod__ = fun

Parameters

fun

A function that takes the form

function (id, args) { . . . }

id

The name of the non-existent method that was called

args

An array of the arguments passed to the method

Description

By default, an attempt to call a method that doesn't exist on an object results in a TypeError being thrown. This behavior can be circumvented by defining a function at that object's __noSuchMethod__ member. The function takes two arguments, the first is the name of the method attempted and the second is an array of the arguments that were passed in the method call. The second argument is an actual array (that is, it inherits through the Array.prototype chain) and not the array-like arguments object.

If this method cannot be called, either as if undefined by default, if deleted, or if manually set to a non-function, the JavaScript engine will revert to throwing TypeErrors.