var exports = this;

(function($){
 var mod = {};
 //返回Controller模型
 mod.create = function(includes){
  var result = function(){
   this.init.apply(this, arguments);
  };

  result.fn = result.prototype;
  
  result.fn.init = function(){};
  result.proxy = function(func){
   return $.proxy(func, this);
  };
  result.fn.proxy = result.proxy;

  result.include = function(ob){
   $.extend(this.fn, ob);
  };
  result.extend = function(ob){
   $.extend(this, ob);
  };
  //将传入的对象扩展制模型
  if(includes) result.include(includes);

  return result;

 };

 exports.Controller = mod;


})(jQuery);

//在文档加载完毕后创建控制器
jQuery(function($){
 var ToggleView = Controller.create({
  init: function(view){
   this.view = $(view);
   this.view.bind('mouseover',true, this.proxy(this.toggleClass));
   this.view.bind('mouseout',false, this.proxy(this.toggleClass));
  },
  toggleClass: function(e){
   this.view.toggleClass('over', e.data);
  }
 });

 //实例化控制器, 调用init();
 var tv = new ToggleView('#view');
 console.log(tv);
});

==================这里是分割线====================

这种方式创建的控制器模型,是在文档加载完毕后才初始化控制器
 
 
 
 
 

相关文章:

  • 2021-07-09
  • 2022-01-05
  • 2021-05-26
  • 2021-09-06
  • 2022-12-23
  • 2021-06-17
  • 2022-01-25
猜你喜欢
  • 2021-09-30
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
相关资源
相似解决方案