いくつかの新しい関数を追加し、すでに存在するいくつかの関数をオーバーライドするために拡張したいprototype.jsクラスがあります。
以下の例では、initAutocompleteNewを追加し、initAutocompleteを編集して「new」を警告します。
Varien.searchForm = Class.create();
Varien.searchForm.prototype = {
initialize : function(form, field, emptyText){
this.form = $(form);
this.field = $(field);
this.emptyText = emptyText;
Event.observe(this.form, 'submit', this.submit.bind(this));
Event.observe(this.field, 'focus', this.focus.bind(this));
Event.observe(this.field, 'blur', this.blur.bind(this));
this.blur();
},
//////more was here
initAutocomplete : function(url, destinationElement){
alert("old");
},
}
誰かが提案しましたが、それはうまくいきません私はそれがjQueryだと思いますか?
$.extend(obj_name.prototype, {
newfoo : function() { alert('hi #3'); }
}