枚舉JavaScript對象的函數(shù)
更新時間:2006年12月22日 00:00:00 作者:
From: JavaEye.com
枚舉JavaScript對象的函數(shù):
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對象的函數(shù):
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>
相關文章
通過循環(huán)優(yōu)化 JavaScript 程序
這篇文章主要介紹了通過循環(huán)優(yōu)化 JavaScript 程序,對于提高 JavaScript 程序的性能這個問題,最簡單同時也是很容易被忽視的方法就是學習如何正確編寫高性能循環(huán)語句。下面我們來學習一下吧2019-06-06
ajax讀取數(shù)據(jù)后使用jqchart顯示圖表的方法
這篇文章主要介紹了ajax讀取數(shù)據(jù)后使用jqchart顯示圖表的方法,涉及Ajax操作及圖表插件的相關使用技巧,需要的朋友可以參考下2015-06-06
JavaScript實現(xiàn)省市區(qū)三級聯(lián)動
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)省市區(qū)三級聯(lián)動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-02-02
小程序按鈕避免多次調用接口和點擊方案實現(xiàn)(不用showLoading)
這篇文章主要介紹了小程序按鈕避免多次調用接口和點擊方案實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04
從jQuery.camelCase()學習string.replace() 函數(shù)學習
camelCase函數(shù)的功能就是將形如background-color轉化為駝峰表示法:backgroundColor。2011-09-09
Bootstrap select多選下拉框實現(xiàn)代碼
這篇文章主要為大家詳細介紹了Bootstrap select多選下拉框實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下代碼2016-12-12

