출처: JavaEye.com
枚举JavaScript对象的函数:
function iterator(obj) {
for (var property in obj) {
document.writeln("
" 속성 " : " obj[속성] "
");
}
}
一个简单示例(test.js):
function Employee () {
this.name = "";
this.dept = "일반";
}
function Manager() {
this.reports = [];
}
Manager.prototype = 새 직원();
함수 WorkerBee() {
this.projects = [];
}
WorkerBee.prototype = 새 직원();
함수 SalesPerson() {
this.dept = "판매";
this.quota = 100;
}
SalesPerson.prototype = new WorkerBee();
function 엔지니어() {
this.dept = "엔지니어링";
this.machine = "";
}
Engineer.prototype = new WorkerBee();
Engineer.prototype.specialty = "코드";
함수 반복자(obj) {
for (var property in obj) {
document.writeln("
" property " : " obj[property] "
");
}
}
HTML页face为:
JavaScript p {
글꼴 크기: 12px;
글꼴 모음: Verdana; 줄 높이: 0.5em;
}
<script></script> <script> <BR> engineer = new Engineer(); <BR> iterator(engineer); <br><br></script>