手机
当前位置:查字典教程网 >编程开发 >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中的this指向

简单介绍JavaScript的变量和数据类型

浅析JavaScript中的事件机制

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

javascript生成不重复的随机数

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

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

JavaScript常用函数工具集:lao-utils

JavaScript正则表达式之multiline属性的应用

简介JavaScript中toUpperCase()方法的使用

精品推荐
分类导航