Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Like Ruby's method_missing but for JabaScript
JavaScript
branch: master
Failed to load latest commit information.
spec letting prettier heads prevail
src letting prettier heads prevail
LICENSE first checkin
README.md first checkin

README.md

method-missing.js

Simulates Ruby's method_missing but in JavaScript.

Usage

function Receiver() {
  this.calls = [];
}

Receiver.prototype.methodMissing(sym, args) {
  args ?
    this.calls.push([sym, args]) :
    this.calls.push(sym);
}

var receiver = new Receiver();

MM(receiver, function() {
  // this == receiver
  this.foo();
  this.bar()
  this.fizz('buzz');
});

receiver.calls[0] //=> 'foo'
receiver.calls[1] //=> 'bar'
receiver.calls[2] //=> ['fizz', ['buzz]]

receiver.foo  //=> undefined
receiver.bar  //=> undefined
receiver.fizz //=> undefined
Something went wrong with that request. Please try again.