Improve this snippet from a prototype class

Posted by seengee on Stack Overflow See other posts from Stack Overflow or by seengee
Published on 2010-05-12T10:05:10Z Indexed on 2010/05/12 11:04 UTC
Read the original article Hit count: 243

This is a snippet from a prototype class i am putting together. The scoping workaround feels a little hacky to me, can it be improved or done differently?

var myClass = Class.create({
    initialize: function() {
        $('formid').getElements().each(function(el){
            $(el).observe("blur", function(){
                this.validateEl(el);
            }.bind(this,el));
        },this);
     },
    validateEl: function(el){
      // validate $(el) in here...
    }
});

Also, it seems to me that i could be doing something like this for the event observers:

$('formid').getElements().invoke("observe","blur" ...

Not sure how i would pass the element references in though?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype