博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ExtJs 源码
阅读量:4481 次
发布时间:2019-06-08

本文共 5740 字,大约阅读时间需要 19 分钟。

createSequence :方法的执行顺序。

createSequence : function(fcn, scope){        if(typeof fcn != "function"){            return this;        }        var method = this;        return function() {            var retval = method.apply(this || window, arguments);            fcn.apply(scope || this || window, arguments);            return retval;        };    }
Function.prototype.sequence=function(fcn, scope){        if(typeof fcn != "function"){            return this;                  //这个this,就是调用sequence的方法,是方法本身,不是方法的实例        }        var method = this;        return function() {            var retval = method.apply(this || window, arguments);            fcn.apply(scope || this || window, arguments);            return retval;        };    }    var cl = function () { name = "hongda"; alert(name); }    var cl2 = function () { name = "hongda2"; alert(name); }    var cl3 = function () { name = "hongda3"; alert(name); }    var fun = cl.sequence(cl3).sequence(cl2);         fun();        //hongda   hongda3  hongda2

有参数

var cl = function (a) { name = "hongda"; alert(name+"||"+a); }        var cl2 = function (a) { name = "hongda2"; alert(name + "||" + a); }        var cl3 = function (a) { name = "hongda3"; alert(name + "||" + a); }      var fun = cl.createCallback("aaaaaa").sequence(cl3.createCallback("cccccc")).sequence(cl2.createCallback("bbbb"));//    var fun = function () { cl("aa"); } .sequence(function () { cl3("cc"); }).sequence(function () { cl2("bb"); });     // 一样有效, 结构不太好        fun();           //fcn为方法,不是方法的执行,不能用cl("aa").sequence(cl2("bb"))... 这样调用

 看method(this)

Function.prototype.sequence = function (fcn, scope) {            console.log("类");            console.dir(this);            if (typeof fcn != "function") {                return this;            }            var method = this;            return function () {                var args = Array.apply(null, arguments);                console.log("arguments:" + args);                var retval = method.apply(this || window, arguments);  //retval为undefined,下次调用时它就是(method),下次时该方法无效                fcn.apply(scope || this || window, arguments);  //这两个arguments没起到作用,因为都是将方法本身传进来的,方法名没有参数                return retval;            };        } var cl = function () { this.name = "hongda"; alert(this.name); }        cl.school = "cl";        var cl2 = function () { this.name = "hongda2"; alert(this.name); }        cl2.school = "cl2";        var cl3 = function () { this.name = "hongda3"; alert(this.name); }        cl3.school = "cl3";        var fun = cl.sequence("d");

 

extend

extend : function(){            // inline overrides            var io = function(o){                for(var m in o){                    this[m] = o[m];                }            };            var oc = Object.prototype.constructor;                        return function(sb, sp, overrides){                if(typeof sp == 'object'){                    overrides = sp;                    sp = sb;                    sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};                }                var F = function(){}, sbp, spp = sp.prototype;                F.prototype = spp;                sbp = sb.prototype = new F();                sbp.constructor=sb;                sb.superclass=spp;                if(spp.constructor == oc){                    spp.constructor=sp;                }                sb.override = function(o){                    Ext.override(sb, o);                };                sbp.override = io;                Ext.override(sb, overrides);                sb.extend = function(o){Ext.extend(sb, o);};                return sb;            };        }(),
function extend() {            var io = function (o) {                for (var m in o) {                    this[m] = o[m];                }            };            var oc = Object.prototype.constructor;            return function (sb, sp, overrides) {                if (typeof sp == 'object') {                    overrides = sp;                    sp = sb;                    sb = overrides.constructor != oc ? overrides.constructor : function () { sp.apply(this, arguments); };                }                var F = function () { }, sbp, spp = sp.prototype;                F.prototype = spp;                sbp = sb.prototype = new F();                sbp.constructor = sb;                sb.superclass = spp;                if (spp.constructor == oc) {                    spp.constructor = sp;                }                sb.override = function (o) {                    Ext.override(sb, o);                };                sbp.override = io;                Ext.override(sb, overrides);                sb.extend = function (o) { Ext.extend(sb, o); };                return sb;            };        }        var father = function () {            this.name = "hong";            this.age = 23;            this.show = function () {                alert(this.name + "||" + this.age);            }        }        father.prototype.address = "jiangshu";        father.prototype.alert = function () { alert("father"); }        var child = function () {            this.school = "nanjing";        }        child.prototype.country = "china";        child.prototype.say = function () {            alert(this.country);        }        extend()(child, father, { center: "center", email: "hongda@qq.com" });         var c = new child();        var f = new father();        console.dir(child);        console.dir(c);        console.dir(father);        console.dir(f);

得出:father没有变化,没有继承overrides

child继承了override,继承了father相对应的prototype对象,但没有继承father内部的属性,方法。

child原来的prototype对象的成员被删掉了。

转载于:https://www.cnblogs.com/hongdada/archive/2013/01/22/2871258.html

你可能感兴趣的文章
局域网内传输文件速度慢
查看>>
Linux的核心版本(摘抄)
查看>>
CASE表达式
查看>>
后缀自动机
查看>>
zkw线段树
查看>>
asp.net中导出Excel的方法
查看>>
[转]跟紧时代,让你的设计更加popular
查看>>
作业1226
查看>>
mainline.js主线
查看>>
fseek()
查看>>
Python学习笔记——PyQt控件中文字居中显示
查看>>
JAVA环境下利用solrj二次开发SOlR搜索的环境部署常见错误
查看>>
Beta阶段敏捷冲刺前准备
查看>>
mini web框架-3-替换模板
查看>>
Siamese Network简介
查看>>
第六节 MongoDB 状态监控、备份复制及自动分片
查看>>
svg学习(三)rect
查看>>
博客园博文生成章节目录
查看>>
ruby 模块 的引入
查看>>
CI Weekly #21 | iOS 持续集成快速入门指南
查看>>