枚举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页面为:
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com