我是靠谱客的博主 怡然发箍,最近开发中收集的这篇文章主要介绍枚举JavaScript对象的函数,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

From: JavaEye.com

枚举JavaScript对象的函数:
function iterator(obj) {
 for (var property in obj) {
 document.writeln("<p>" + property + " : " + obj[property] + "</p>");
 }
}

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

function Manager() {
  this.reports = [];
}
Manager.prototype = new Employee();

function WorkerBee() {
  this.projects = [];
}
WorkerBee.prototype = new Employee();

function SalesPerson() {
  this.dept = "sales";
  this.quota = 100;
}
SalesPerson.prototype = new WorkerBee();

function Engineer() {
  this.dept = "engineering";
  this.machine = "";
}
Engineer.prototype = new WorkerBee();
Engineer.prototype.specialty = "code";

function iterator(obj) {
 for (var property in obj) {
 document.writeln("<p>" + property + " : " + obj[property] + "</p>");
 }
}

HTML页面为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JavaScript</title>
<style type="text/css">
p {
 font-size: 12px;
 font-family: Verdana;
 line-height: 0.5em;
}
</style>
<script language="javascript" type="text/javascript" src="test.js"></script>
</head>
<body>
<script type="text/javascript">
 engineer = new Engineer();
 iterator(engineer);

</script>
</body>
</html>

最后

以上就是怡然发箍为你收集整理的枚举JavaScript对象的函数的全部内容,希望文章能够帮你解决枚举JavaScript对象的函数所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(171)

评论列表共有 0 条评论

立即
投稿
返回
顶部