枚舉JavaScript對象的函數(shù)
更新時(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>");
}
}
一個(gè)簡單示例(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>");
}
}
一個(gè)簡單示例(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)文章
bootstrap-table.js擴(kuò)展分頁工具欄(增加跳轉(zhuǎn)到xx頁)功能
這篇文章主要介紹了bootstrap-table.js擴(kuò)展分頁工具欄,增加跳轉(zhuǎn)到xx頁功能,由于小編的水平停留在dom級,此次擴(kuò)展只支持頁面上的表格,如果大家有好的建議歡迎提出2017-12-12layui結(jié)合form,table的全選、反選v1.0示例講解
今天小編就為大家分享一篇layui結(jié)合form,table的全選、反選v1.0示例講解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08JavaScript實(shí)現(xiàn)單鏈表過程解析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)單鏈表過程,鏈表中的元素在內(nèi)存中不必是連續(xù)的空間。鏈表的每個(gè)元素有一個(gè)存儲元素本身的節(jié)點(diǎn)和指向下一個(gè)元素的引用。下面請和小編一起進(jìn)入文章了解更多的詳細(xì)內(nèi)容吧2021-12-12手把手教你用Javascript實(shí)現(xiàn)觀察者模式
這篇文章主要為大家介紹了Javascript觀察者模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2021-12-12setinterval()與clearInterval()JS函數(shù)的調(diào)用方法
這篇文章主要介紹了setinterval()與clearInterval()JS函數(shù)的調(diào)用方法,實(shí)例分析了setinterval()與clearInterval()的語法結(jié)構(gòu)及使用技巧,需要的朋友可以參考下2015-01-01js函數(shù)參數(shù)設(shè)置默認(rèn)值的一種變通實(shí)現(xiàn)方法
js函數(shù)中有個(gè)儲存參數(shù)的數(shù)組arguments,因此js版支持參數(shù)默認(rèn)值的函數(shù)可以通過另外一種變通的方法實(shí)現(xiàn)2014-05-05