ExtJs 源码

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对象的成员被删掉了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值