/*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();
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的异步概念。要区分好。