zoukankan      html  css  js  c++  java
  • 第二种简单方式创建模型控制器的方式

    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);
    });

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

    这种方式创建的控制器模型,是在文档加载完毕后才初始化控制器
     
     
     
     
     
  • 相关阅读:
    audio元素
    获取页面中出现次数最多的三个标签以及出现次数
    vue ssr(server side rendering)
    python_2 python的编码声明
    python_1 python的编译过程
    bugs
    isPrototypeOf和 instanceof 的区别
    WebStorm 配置Git
    MongoDB 副本集搭建
    获取结算样式 getComputedStyle-currentStyle
  • 原文地址:https://www.cnblogs.com/willian/p/2880468.html
Copyright © 2011-2022 走看看