Enumerating the functions of JavaScript objects _javascript tips
Source: Internet
Author: User
From:JavaEye.com
To enumerate the functions of a JavaScript object:
function iterator (obj) {
For (Var, in obj) {
Document.writeln ("<p>" + Property + ":" + Obj[property] + "</p>");
}
}
A simple example (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, in obj) {
Document.writeln ("<p>" + Property + ":" + Obj[property] + "</p>");
}
}
The HTML page is:
<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>
<body>
<script type= "Text/javascript" >
Engineer = new Engineer ();
Iterator (engineer);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service