"missing_method" in javascript

Discussion in 'Javascript' started by pedz, Jul 28, 2011.

  1. pedz

    pedz Guest

    Google tells me to "Please try again"... I apologize if this is a duplicatemessage.

    Is there a way to implement the equivalent of the "missing_method" method in Ruby? If you call foo.whatever(args) in Ruby and the whatever method is not defined, then it will call the missing_method method if it is defined passing it "whatever" along with the args.

    I realize that I can implement this with defining a function "blah" and then just do foo.blah("whatever", args) but the "blah" is distracting. It is much clearer to call foo.whatever(args). Is there a way to do that in Javascript?

    Note, that usually the "whatever" is not a single or even a few possible names but is usually a pattern or a large set such that defining all of them is either not possible until run time or impractical.

    Thank you,
    pedz, Jul 28, 2011
    1. Advertisements

  2. Not yet.
    ES6 migth contain proxies which can be used to do this, but the
    current version of ECMAScript can't do it.

    Lasse Reichstein Nielsen, Jul 28, 2011
    1. Advertisements

  3. It sounds as though you're trying to use properties for something they
    aren't good for. Have you considered other ways? E.g holding names in a
    sorted array.

    John G Harris, Jul 28, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.