---
title: "js  oop编程"
author: "lishdfsdf"
date: "2015-10-09T21:43:35Z"
tags: []
categories: ["Web前端"]
slug: "js-oop"
draft: false
lastmod: "2015-10-09T21:43:35Z"
id: 2247944
url: "https://lishdfsdf.iteye.com/blog/2247944"
---

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

//模拟服务器获取数

   

    function test1(callback){

var persons=\[];

for(var i=0;i&lt;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&gt;=0){

count=data;

test();

}

})

 

}

function test3(i,callback){

test1(function(data){

console.info(data\[i]);

callback(--i);

});

}

//绑定数据

//test();