これはオブザーバーデザインパターンと呼ばれています。それは、JQueryやJavaScriptのためには分離されていません。ほとんどのプログラミング言語には多くのデザインパターンを実装できます。
DevShopは、javascriptのデザインパターンのフレームワークです。
OBSERVER
(function(){
DevShop.Me({
Observer:function(obj){
var observer=function(){
this.onRegister=function(){};
this.notify=function(eventName,observable){
this.observable=observable;
if(typeof this[eventName]==="function")
try{this[eventName]();}catch(e){}
};
};
return DevShop.SingletonFactory({extend:observer,instance:obj});
}
});
})();
観測可能
(function(){
DevShop.Me({
Observable:function(obj){
var observable=function(){
this.observers=[];
this.addObserver=function(o){
if(typeof o==="function"||typeof o==="object"){
if(typeof o.notify==="function"){
this.observers.push(o);
if(typeof o.onRegister==="function")
try{o.onRegister();}catch(e){}
}
}
};
this.notifyObservers=function(eventName){
var size=this.observers.length;
for(var x=0;x<size;x++){
try{
this.observers[x].notify(eventName,this);
}catch(e){}
}
};
};
return DevShop.SingletonFactory({extend:observable,instance:obj});
}
});
})();
あなたがここにオブザーバーデザインパターンについての詳細を読むことができます:http://en.wikipedia.org/wiki/Observer_pattern
何ロッキン彼らのObserverパターンは次のようになります答え、そしてすばやく! – jMyles