Sneaky Abstractions

Subscribe to my Feed, follow me on , recommend me on Working With Rails or see my code on GitHub

Comment

You're viewing a comment to the post Unobtrusive Ajax patterns: element state

By tobielangel.com at

For performance and memory consumption issues, you’d be better of instantiating an element wrapper rather than relying on a closure:

function Post(element) {
  this.element = element;
}
Post.prototype = {
  markRead: function(){
    this.element.addClassName('read');
  },
  markUnread: function(){
    this.element.removeClassName('read');
  },
  isRead: function(){
    return this.element.hasClassName('read');
  }
};

And then:

Mysite.posts = $$('.post').map(function(el){
  return new Post(el);
});

Super Disco Breakin