Its not much different, but this is what i do:

if ( $('some_button') ) {
  $('some_button').observe('click', function (e) {
    //do stuff.
  });
}


Ideally, i wish prototype was a bit more strict about this stuff...

If you're using Firebug, you could replace your $() definition:

function $(element) {
  if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length;
i++)
      elements.push($(arguments[i]));
    return elements;
  }
*  if (Object.isString(element)) {
    var _element  = element;
            element  = document.getElementById(element);

    if ( element == null ) {
      console.log('"' + _element + '" is null or does not exist');
      return;
    }
  }
*  return Element.extend(element);
}







On Fri, Sep 18, 2009 at 4:17 PM, Luisgo <lgo...@gmail.com> wrote:

>
> Hey all,
>
> I was wondering if you can suggest a better way of achieving what this
> snippet does. I do it often enough that it starts bloating my code and
> frankly just gets annoying to type.
>
>   var some_button = $('some-button')
>   if ( some_button ) {
>     some_button.observe("click",function(event){
>       event.stop();
>       form_object.save();
>     });
>   }
>
> I can compress it a bit by doing this:
>
>   if ( some_button = $('some-button') ) {
>     some_button.observe("click",function(event){
>       event.stop();
>       form_object.save();
>     });
>   }
>
> But that's little consolation.
>
> In an ideal world I would want to do something close to:
>
>   $('some-button').observe("click",function(){
>     form_object.save();
>   }, false );
>
> Note: that "false" parameter would replace event.stop() which happens
> often enough. Defaults to true.
>
> Or even like (I know it looks like JQuery):
>
>   $('some-button').click(function(){
>     form_object.save();
>   },false);
>
> Any ideas/suggestions?
>
> Thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to