jQuery: inherit functions to several objects

Posted by Fuxi on Stack Overflow See other posts from Stack Overflow or by Fuxi
Published on 2009-11-28T16:04:02Z Indexed on 2010/06/07 17:02 UTC
Read the original article Hit count: 208

Filed under:
|
|

hi,

i made several table-based-widgets (listview-kind-of) which all have the same characteristics: styling odd/even rows, hover on/off, set color onClick, deleting a row when clicking on trash-icon.

so it's always the same (prototype-)code for each widget. is there a way to have the code only once then simply apply/inherit it to all widgets?

2nd, here's some of the code - could this be optimized?

var me = this;
$("tr",this.table).each(function(i)
{
	var tr = $(this);
	tr.bind("mouseover",function(){me.hover(tr,true)});
	tr.bind("mouseout",function(){me.hover(tr,false)});
	tr.bind("click",function(){me.Click(tr)});
});
$("tr").filter(":odd").addClass("odd");

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about functions