枚舉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>
相關(guān)文章
通過循環(huán)優(yōu)化 JavaScript 程序
這篇文章主要介紹了通過循環(huán)優(yōu)化 JavaScript 程序,對于提高 JavaScript 程序的性能這個問題,最簡單同時也是很容易被忽視的方法就是學(xué)習(xí)如何正確編寫高性能循環(huán)語句。下面我們來學(xué)習(xí)一下吧2019-06-06
ajax讀取數(shù)據(jù)后使用jqchart顯示圖表的方法
這篇文章主要介紹了ajax讀取數(shù)據(jù)后使用jqchart顯示圖表的方法,涉及Ajax操作及圖表插件的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
JavaScript實現(xiàn)省市區(qū)三級聯(lián)動
這篇文章主要為大家詳細(xì)介紹了JavaScript實現(xiàn)省市區(qū)三級聯(lián)動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-02-02
Javascript this 的一些學(xué)習(xí)總結(jié)
相信有C++、C#或Java等編程經(jīng)驗的各位,對于this關(guān)鍵字再熟悉不過了。由于Javascript是一種面向?qū)ο蟮木幊陶Z言,它和C++、C#或Java一樣都包含this關(guān)鍵字,接下來我們將向大家介紹Javascript中的this關(guān)鍵字2012-08-08
小程序按鈕避免多次調(diào)用接口和點擊方案實現(xiàn)(不用showLoading)
這篇文章主要介紹了小程序按鈕避免多次調(diào)用接口和點擊方案實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
uni-app跨端自定義指令實現(xiàn)按鈕權(quán)限操作
實現(xiàn)uni-app自定義指令按鈕權(quán)限需要涉及到對于vue.config.js新增loader配置,基礎(chǔ)正則知識,webpack的loader開發(fā)和調(diào)試,以及npm本地調(diào)試和發(fā)布,接下來就從了解這些前置知識開始,需要的朋友可以參考下2023-01-01
Knockoutjs 學(xué)習(xí)系列(一)ko初體驗
本篇主要簡單介紹了knockoutjs中最重要的概念:可觀察對象(數(shù)組)。非常不錯具有參考借鑒價值,感興趣的朋友快來圍觀吧2016-06-06
從jQuery.camelCase()學(xué)習(xí)string.replace() 函數(shù)學(xué)習(xí)
camelCase函數(shù)的功能就是將形如background-color轉(zhuǎn)化為駝峰表示法:backgroundColor。2011-09-09
Bootstrap select多選下拉框?qū)崿F(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Bootstrap select多選下拉框?qū)崿F(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下代碼2016-12-12

