• Ext下的方法


    addBehaviors:批量添加事件

    Ext.addBehaviors({
        // 在id为foo的元素中的所有锚点上添加一个单击事件的侦听器
        '#foo a@click' : function(e, t){
            // 做一些事情
        },
    
        // 把相同的监听器添加到多个选择符上(在@符号前使用逗号分隔)
        '#foo a, #bar span.some-class@mouseover' : function(){
            // 做一些事情
        }
    });
            addBehaviors: function(o){
                //初始化前处理
                if(!Ext.isReady){
                    Ext.onReady(function(){
                        Ext.addBehaviors(o);
                    });
                } else {
                    var cache = {}, 
                        parts,//命令分析结果[]
                        b,//命令
                        s;//选择器
                    for (b in o) {
                        //选择器@事件
                        if ((parts = b.split('@'))[1]) { 
                            s = parts[0];
                            if(!cache[s]){
                                cache[s] = Ext.fly(document).select(s, true);
                            }
                            //初始化参数
                            cache[s].on(parts[1], o[b]);
                        }
                    }
                    cache = null;
                }
            }

    application:Ext.app.application的快捷方式

    Ext.application({
        name: 'MyApp',
        launch: function() {
            Ext.create('Ext.container.Viewport', {
                items: {
                    html: 'My App'
                }
            });
        }
    });
    Ext.application = function(config) {
        //创建应用
        var createApp = function (App) {
                Ext.onReady(function() {
                    Ext.app.Application.instance = new App();
                });
            },
            paths = config.paths,
            ns;
    
        if (typeof config === "string") {
            //字符串代理
            Ext.require(config, function() {
                createApp(Ext.ClassManager.get(config));
            });
        }
        else {
            //config配置
            config = Ext.apply({
                extend: 'Ext.app.Application' 
            }, config);
            
            Ext.Loader.setPath(config.name, config.appFolder || 'app');
            //依赖关系
            if (paths) {
                for (ns in paths) {
                    if (paths.hasOwnProperty(ns)) {
                        Ext.Loader.setPath(ns, paths[ns]);
                    }
                }
            }
    
            config['paths processed'] = true;
    
            //配置后加载对象
            Ext.define(config.name + ".$application", config,
                function () {
                    createApp(this);
                });
        }
    };

    apply:常用于覆盖,约等于$.extend

    Ext.apply({a:1},{b:2});//{a:1,b:2}
        Ext.apply = function(object, config, defaults) {
            if (defaults) {
                //嵌套
                Ext.apply(object, defaults);
            }
    
            if (object && config && typeof config === 'object') {
                var i, j, k;
                //浅拷贝
                for (i in config) {
                    object[i] = config[i];
                }
    
                //['valueOf', 'toLocaleString', 'toString', 'constructor']枚举对虾|null,低版本复制
                if (enumerables) {
                    for (j = enumerables.length; j--;) {
                        k = enumerables[j];
                        if (config.hasOwnProperty(k)) {
                            object[k] = config[k];
                        }
                    }
                }
            }
    
            return object;
        }

    applyif:常用于默认参数初始化,apply参数倒排排列

    Ext.applyIf({a:1,b:2},{b:3,c:4});//{a: 1, b: 2, c: 4}
            //主要用于默认参数配置,没有嵌套和枚举兼容
            applyIf: function(object, config) {
                var property;
    
                if (object) {
                    for (property in config) {
                        if (object[property] === undefined) {
                            object[property] = config[property];
                        }
                    }
                }
    
                return object;
            },

    bind:Ext.Function.bind的快捷方式

    var fn=Ext.bind(function(){console.log(this,arguments)},{},[1,2,3],true);
    fn(('a','b','c','d');//Object {} ["a", "b", "c", "d", 1, 2, 3]
        bind: function(fn, scope, args, appendArgs) {
            //仅包含两个参数,作用域封装-->代理函数
            if (arguments.length === 2) {
                return function() {
                    return fn.apply(scope, arguments);
                };
            }
    
            var method = fn,
                slice = Array.prototype.slice;
    
            return function() {
                //参数覆盖
                var callArgs = args || arguments;
                //追加or指定修改位置
                if (appendArgs === true) {
                    callArgs = slice.call(arguments, 0);
                    callArgs = callArgs.concat(args);
                }
                else if (typeof appendArgs == 'number') {
                    callArgs = slice.call(arguments, 0); 
                    Ext.Array.insert(callArgs, appendArgs, args);
                }
    
                return method.apply(scope || Ext.global, callArgs);
            };
        },

    callback:Function.call,apply,Ext.defer的封装(含参数数组话)

    Ext.callback('a',{a:function(){console.log(this,arguments)}},[1,2,3],5000);//执行作用域下的方法,并传递参数,延迟时间
    Ext.callback(function(){console.log(this,arguments)},{},[1,2,3],5000);//回调方法,并传递参数,延迟时间
     //方法,作用域,参数,延迟毫秒
        callback: function (callback, scope, args, delay, caller, defaultScope) {
            if (!callback) {
                return;
            }
            var preventClimb = scope === 'this' || scope === 'controller';
            //字符串...
            if (callback.charAt) { 
                if ((!scope || preventClimb) && caller) {
                    scope = caller.resolveListenerScope(preventClimb ? scope : defaultScope);
                }
                if (!scope || !Ext.isObject(scope)) {
                    Ext.Error.raise('Named method "' + callback + '" requires a scope object');
                }
                if (!Ext.isFunction(scope[callback])) {
                    Ext.Error.raise('No method named "' + callback + '" on ' +
                                    (scope.$className || 'scope object'));
                }
    
                callback = scope[callback];
            } else if (preventClimb) {
                scope = defaultScope || caller;
            } else if (!scope) {
                scope = caller;
            }
            
            var ret;
    
            if (callback && Ext.isFunction(callback)) {
                scope = scope || Ext.global;
                if (delay) {
                    //delay毫秒后执行
                    Ext.defer(callback, delay, scope, args);
                } else if (args) {
                    //参数调用
                    ret = callback.apply(scope, args);
                } else {
                    //无参调用
                    ret = callback.call(scope);
                }
            }
    
            return ret;
        },

    clone:克隆

    copyTo:选择性copy属性

    Ext.copyTo({}, {a:1,b:2,c:3}, 'a,b');//Object {a: 1, b: 2}
    Ext.copyTo({}, {a:1,b:2,c:3}, ['a','b','e'],true);//Object {a: 1, b: 2, e: undefined}
        //结果,来源,所需属性,强制增加key
        copyTo : function(dest, source, names, usePrototypeKeys){
            if(typeof names == 'string'){
                names = names.split(/[,;s]/);
            }
    
            var n,
                nLen = names? names.length : 0,
                name;
    
            for(n = 0; n < nLen; n++) {
                name = names[n];
    
                if (usePrototypeKeys || source.hasOwnProperty(name)){
                    dest[name] = source[name];
                }
            }
    
            return dest;
        },

    create:无 new实例化,自带加载器,关键是可以用它动它new,类似于//与RegExp

    createByAlias:-->Ext.ClassManager.instantiateByAlia

    decode:-->Ext.json.decode

    defer:setTimout的封装

    define:定义

    destory:批量调用对象的destory

    destroyMembers:删除并返回

    each:循环

    encode:-->Ext.JSON.encode

    exclude:-->Ext.Loader.exclude

    fly:-->Ext.dom.AbstractElement.fly

    iterate:掉用object/array的each

    log:浏览器日志封装

    merge:Ext.Object.merge

    ns,namespace:命名空间

    override:重载,复制,继承的语意话封装

    pass:-->Ext.Function.pass

    preg:-->Ext.PluginManager.registerType

    query:-->Ext.dom.Query.select

    regStore:注册store

    require:Ext.Loader.require

    select:css选择器

    各个get,is函数

    以上封装大多为闭包化(作用域),相似功能封装,不同业务区分以及快捷方式

  • 相关阅读:
    Use 'mysqld --thread_stack=#' to specify a bigger stack.
    Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax;
    interface interface com.alibaba.dubbo.common.compiler.Compiler, class line com.alibaba.dubbo.common.compiler.support.JavassistCompiler) in
    javax.servlet.http.HttpServlet was not found on the Java Build Path
    js_jquery单机事件不起作用
    JavaScript 执行环境及作用域
    闭包的使用场景
    YUI css reset
    比较经典的数组去重和数组排序
    css 响应式布局
  • 原文地址:https://www.cnblogs.com/liuCy/p/4959964.html
Copyright © 2020-2023  润新知