20 Javascript for ... 语法
|
|
- 这个语句使用户可以叠代一个对象的所有特性
- for ( variable in object ) { // 生成 Form
- 一系列语句 }
- function dump_props(obj, obj_name) {
- var result = "";
- for( var i in obj) {
- result += obj_name + "." + i + " = " + obj[i]
+ "<BR>"; }
- result += "<HR>";
- return result;
- }
- 这里 i runs over names of Properties and obj[i] is actual property
- 注意用户提供 obj 和 obj_name
- function car(make,model) { // 一个例子
- this.make = make;
- this.model = model; }
- mycar = new car("Ford","Explorer");
- document.writeln(dump_props(mycar,"mycar"));
Copyright: NPACT |
|