Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > "missing_method" in javascript

Reply
Thread Tools

"missing_method" in javascript

 
 
pedz
Guest
Posts: n/a
 
      07-28-2011
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
 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      07-28-2011
pedz <(E-Mail Removed)> writes:

> 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.


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

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

 
Reply With Quote
 
 
 
 
John G Harris
Guest
Posts: n/a
 
      07-28-2011
On Wed, 27 Jul 2011 at 18:30:57, in comp.lang.javascript, pedz wrote:
>Google tells me to "Please try again"... I apologize if this is a
>duplicate message.
>
>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.


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
--
John Harris
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generated JavaScript vs. Manually Created JavaScript: Which one comes first? Nathan Sokalski ASP .Net 4 11-08-2007 07:24 AM
JavaScript or not JavaScript Mark Rae ASP .Net 36 09-09-2006 01:12 PM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
Javascript -> Applet: variable reset after method call from javascript?! mcdeveloper Java 1 06-13-2006 08:34 AM
To Javascript, or not to Javascript Shane NZ Computing 5 08-30-2005 09:33 PM



Advertisments