forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinspect.as
More file actions
39 lines (30 loc) · 1.13 KB
/
inspect.as
File metadata and controls
39 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package utils.object {
import flash.utils.describeType;
/**
* Scan an Object.
* @param obj Object to be scanned
* @param depth Depth of scanning
* @return Scan result
*/
public function inspect(obj:Object, depth:int = 10, prefix:String = "\t"):String {
var scan:Function = function(obj:Object, depth:int, prefix:String):String {
var out:String;
if(depth < 1) {
out = obj is String ? "\"" + obj + "\"" : String(obj);
} else {
const classDef:XML = describeType(obj);
var str:String = "";
for each(var variable:XML in classDef.variable) {
str += prefix + variable.@name + " = " + scan(obj[variable.@name], depth - 1, prefix + "\t") + "\n";
}
for(var s:String in obj) {
str += prefix + s + "=" + scan(obj[s], depth - 1, prefix + "\t") + "\n";
}
//noinspection NestedConditionalExpressionJS,NegatedConditionalExpressionJS
out = str == "" ? ((obj != null) ? (obj is String ? "\"" + obj + "\"" : obj + "") : "null") : ("[" + classDef.@name + "] {\n" + str + (prefix.substr(0, prefix.length - 1)) + "}");
}
return out;
};
return prefix + scan(obj, depth, prefix + "\t");
}
}