Ah scusa, per la fretta mi sono dimenticato che ovviamente la funzione deve anche ritornare l'oggetto:
In ogni caso questo è solo un esempio: se vuoi applicarlo andrebbero fatti vari miglioramenti ( ad esempio verificare se l'elemento ha già i metodi in modo da non doverli nuovamente applicare... )codice:function $(id) { var el = document.getElementById(id); for(var i in $.methods) { if(typeof($.methods[i]) == 'function') el[i] = $.methods[i]; } return el; }
Comunque ti ripeto, è molto meglio questo approccio:
Codice PHP:function $(id) {
return new $.klass(document.getElementById(id));
}
$.klass = function(el) {
this.el = el;
}
$.klass.prototype = {
'test': function() {
alert(this.el.tagName);
}
}

Rispondi quotando