枚举JavaScript对象的函数:
function iterator(obj) {
for (var property in obj) {
document.writeln("
" + property + " : " + obj[property] + "
");一个简单示例(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("
" + property + " : " + obj[property] + "
");HTML页面为:
Copyright © 2019- efsc.cn 版权所有 赣ICP备2024042792号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务