欢迎来到福编程网,本站提供各种互联网专业知识!

枚举JavaScript对象的函数

发布时间:2006-12-22 作者: 来源:转载
From:JavaEye.com枚举JavaScript对象的函数:functioniterator(obj){for(varpropertyinobj){document.writeln(""+property+":"+obj[property]+"");}}一个简单示例(test.js):functionEmployee(){this.name="";this.dept="general";}functionManager
From:JavaEye.com

枚举JavaScript对象的函数:
functioniterator(obj){
for(varpropertyinobj){
document.writeln("

"+property+":"+obj[property]+"

");
}
}

一个简单示例(test.js):
functionEmployee(){
this.name="";
this.dept="general";
}

functionManager(){
this.reports=[];
}
Manager.prototype=newEmployee();

functionWorkerBee(){
this.projects=[];
}
WorkerBee.prototype=newEmployee();

functionSalesPerson(){
this.dept="sales";
this.quota=100;
}
SalesPerson.prototype=newWorkerBee();

functionEngineer(){
this.dept="engineering";
this.machine="";
}
Engineer.prototype=newWorkerBee();
Engineer.prototype.specialty="code";

functioniterator(obj){
for(varpropertyinobj){
document.writeln("

"+property+":"+obj[property]+"

");
}
}

HTML页面为:



JavaScript

p{
font-size:12px;
font-family:Verdana;
line-height:0.5em;
}





engineer=newEngineer();
iterator(engineer);



相关推荐