枚举JavaScript对象的函数_javascript技巧
程序员文章站
2022-05-07 10:38:31
...
From: JavaEye.com
枚举JavaScript对象的函数:
function iterator(obj) {
for (var property in obj) {
document.writeln("
}
}
一个简单示例(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("
}
}
HTML页面为:
JavaScript
枚举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页面为:
上一篇: wamp下安装thread扩展
下一篇: Oracle trunc()函数的用法
推荐阅读
-
js类的静态属性和实例属性的理解_javascript技巧
-
js实现简单选项卡与自动切换效果的方法_javascript技巧
-
javascript 数据存储的常用函数总结
-
鼠标移到div,浮层显示明细,弹出层与div的上边距左边距重合(示例代码)_javascript技巧
-
javascript 面向对象的经典实例代码_js面向对象
-
JS实现点击链接取消跳转效果的方法_javascript技巧
-
JS中获取数据库中的值的方法_javascript技巧
-
js Li来实现的效果_javascript技巧
-
js 自定义的联动下拉框_javascript技巧
-
可以读取EXCEL文件的js代码_javascript技巧