几行脚本让你看出Javascript端倪

/*function Car(){
    this.method1 = function(){
        this.method2 = function(){
            (this.method3 = function($){
                if(!($ instanceof Car))
                    console.log($);
                    
            })(this);
            return this;
        }
        return this;
    }
}
var car = new Car();
car.method1().method2().method3("abc");*/

/*function Car(){
    this.method1 = function(){
        console.log(this);
    }
    return this.method1; //这里返回的是Object;
}
var car = new Car();
var obj = new car(); //这里的obj应该是一个Object对象,而不是什么Car,Window等等。*/


//(function Car(){
//    //console.log(this); //使用闭包,这里的this就全然变成window,类似于window.Car()这样的调用。
//    this.method1 = function(){
//        console.log(this);
//    }
//    return this.method1;
//})()();
window.method1();//自然这里的window.method1()就可用了。


test = function Car(){
    this.method1 = function(){
        console.log(this);
    }
    return this.method1;
};

var func = new window.test();
var obj = new func();

console.log(obj instanceof Object); //这里我们再次把obj变成了Object类型的对象



扩展:include 与 extends


function Cat(){
        
}
Cat.prototype.say = function(){
    console.log("Miaw");    
}
function Car(){}

Car.fn = Car.prototype;
Car.fn.extends = function(obj){    
    for(i in obj){
        this[i] = obj[i];//这里是给类添加实例方法;    
        //Car[i] = obj[i];//这里是给类添加静态方法;
    }
}

//下面让Car从Cat那边扩展并可以说话
var car = new Car();
car.extends(new Cat());
car.say();//类的实例方法调用;
//Car.say();//类的静态方法调用;


另外注意:UML中活动图的同步是锁机制,要是想表达更详尽的Ajax异步,需要去时序图中表达,活动图中的异步不是Ajax的异步概念,活动图是线程同步锁概念,而时序图才是Ajax的异步概念。要区分好。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值