chinmay schrieb:
Hi all,

Usually, I'm this lurker who scrapes this list for tips to improve my
jquery code. As a beginner, I can't begin to tell you how useful it's
been.

I was just wondering: Can we have a method_missing or similar
exception-catching scheme for jQuery? Dunno about you, but I'm pretty
impressed with Rails dynamic finders (like find_by_name_and_city()
etc. Perhaps a $(form).find_all_selected() ? )

Maybe we could even use it to reduce the footprint of the core jQuery
script on a page, pulling extra functionality from the server if we
find a method_missing.

Can anyone see any use for this? And if someone wants to code this,
tell me; I'm all game to learn!
I don't know how exactly method_missing works in Ruby, but I don't know of a similar language feature in JavaScript.

Whenever I write code that relies on some optional code, it looks like this:

if ( someObject.someProperty ) {
   // do something with that property
}

To avoid more then one check of this type in a script you can write a replacement implementation:

// at the start of your script
if ( !someObject.someProperty ) {
        someObject.someProperty = function() {};
}
...
// now use someProperty and nothing happens when it doesn't exist yet
someObject.someProperty()

--
Jörn Zaefferer

http://bassistance.de

Reply via email to