This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.


The __noSuchMethod__ property references a function to be executed when a non-existent method is called on an object.


obj.__noSuchMethod__ = fun


A function that takes the form
function (id, args) { . . . }
The name of the non-existent method that was called
An array of the arguments passed to the method


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.


Example: Simple test of __noSuchMethod__

var o = {
  __noSuchMethod__: function (id, args) { console.log(id, '(' + args.join(', ') + ')'); }

// Output
"foo" "(1, 2, 3)"
"bar" "(4, 5)"
"baz" "()"

Using __noSuchMethod__ to simulate multiple inheritance

An example of code that implements a primitive form of multiple inheritance is shown below.

// Doesn't work with multiple inheritance objects as parents

function noMethod(name, args) {
  var parents=this.__parents_;
  // Go through all parents
  for (var i=0;i<parents.length;i++) {
    // If we find a function on the parent, we call it
    if (typeof parents[i][name] =="function") {
      return parents[i][name].apply(this, args);
  // If we get here, the method hasn't been found
  throw new TypeError;

// Used to add a parent for multiple inheritance

function addParent(obj, parent) {
  // If the object isn't initialized, initialize it
  if (!obj.__parents_) {
  // Add the parent

An example of using this idea is shown below.

// Example base class 1

function NamedThing(name){;

NamedThing.prototype = {
  getName: function() {return;},
  setName: function(newName) {;}

//Example base class 2

function AgedThing(age){

AgedThing.prototype = {
  getAge: function(){return this.age;},
  setAge: function(age){this.age=age;}

// Child class. inherits from NamedThing and AgedThing as well as defining address

function Person(name, age, address){
  addParent(this, NamedThing.prototype);, name);
  addParent(this, AgedThing.prototype);, age);

Person.prototype = {
  getAddr: function() {return this.address;},
  setAddr: function(addr) {this.address=addr;}

var bob=new Person("bob", 25, "New York");

console.log("getAge is "+(("getAge" in bob)?"in":"not in")+" bob");
console.log("bob's age is: "+bob.getAge());
console.log("getName is "+(("getName" in bob)?"in":"not in")+" bob");
console.log("bob's name is: "+bob.getName());
console.log("getAddr is "+(("getAddr" in bob)?"in":"not in")+" bob");
console.log("bob's address is: "+bob.getAddr());


Not part of any specifications.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support Not supported 1.0 (1.7 or earlier) Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported Not supported 1.0 (1.0) Not supported Not supported Not supported


Document Tags and Contributors

 Last updated by: Sevenspade,