手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >枚举JavaScript对象的函数
枚举JavaScript对象的函数
摘要:From:JavaEye.com枚举JavaScript对象的函数:functioniterator(obj){for(varpropert...

From:JavaEye.com

枚举JavaScript对象的函数:

functioniterator(obj){

for(varpropertyinobj){

document.writeln("<p>"+property+":"+obj[property]+"</p>");

}

}

一个简单示例(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("<p>"+property+":"+obj[property]+"</p>");

}

}

HTML页面为:

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>

<title>JavaScript</title>

<styletype="text/css">

p{

font-size:12px;

font-family:Verdana;

line-height:0.5em;

}

</style>

<scriptlanguage="javascript"type="text/javascript"src="test.js"></script>

</head>

<body>

<scripttype="text/javascript">

engineer=newEngineer();

iterator(engineer);

</script>

</body>

</html>

【枚举JavaScript对象的函数】相关文章:

在JavaScript的正则表达式中使用exec()方法

javascript动态创建链接的方法

JavaScript获取两个数组交集的方法

Javascript技术栈中的四种依赖注入小结

JavaScript的while循环的使用

javascript实现简单的进度条

Javascript实现div层渐隐效果的方法

详解Javascript中的Object对象

详解JavaScript中Date.UTC()方法的使用

讲解JavaScript中for...in语句的使用方法

精品推荐
分类导航