国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

枚舉JavaScript對象的函數

2019-11-21 02:24:22
字體:
來源:轉載
供稿:網友
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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 祁门县| 望谟县| 承德市| 盘锦市| 武陟县| 稷山县| 通道| 黄石市| 安庆市| 蓝山县| 凉城县| 灌南县| 鄯善县| 山西省| 革吉县| 邛崃市| 永康市| 嘉鱼县| 塘沽区| 民权县| 哈密市| 大名县| 达尔| 化州市| 西和县| 融水| 永济市| 阿勒泰市| 阳城县| 邹平县| 华安县| 尉氏县| 辛集市| 合江县| 肥东县| 米林县| 奎屯市| 焉耆| 阜新市| 曲沃县| 喜德县|