ITeye博客

js oop编程

lishdfsdf · 2015-10-09 21:43 · javascript · Web前端 · Markdown

//###########################################################################################################

//模拟服务器获取数

   

    function test1(callback){

var persons=[];

for(var i=0;i<10;i++){

var p=new person(i,'小白'+i+'号');

 

persons.push(p);

}

window.setTimeout(function(){

callback(persons)

},50);

 

};

/**

* 人类

*/

function person(id,name){

this.id=id;

this.name=name;

 

}

//通过原型声明函数  使用 this  访问类的属性或函数

person.prototype={

test:function(){

alert('haha')

},

getId:function(){

alert(this.id);

}

}

var p=new person(1,'小白号');

p.test();

p.getId();

 

//###########################################################################################################

//客户端

var count=9;

function test(){

//模拟循环查询数据

test3(count,function(data){

if(data>=0){

count=data;

test();

}

})

 

}

function test3(i,callback){

test1(function(data){

console.info(data[i]);

callback(--i);

});

}

//绑定数据

//test();

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。