| 1 |
/**@constructor*/ |
| 2 |
function Reflection(obj) { |
| 3 |
this.obj = obj; |
| 4 |
} |
| 5 |
|
| 6 |
Reflection.prototype.getConstructorName = function() { |
| 7 |
if (this.obj.constructor.name) return this.obj.constructor.name; |
| 8 |
var src = this.obj.constructor.toSource(); |
| 9 |
var name = src.substring(name.indexOf("function")+8, src.indexOf('(')).replace(/ /g,''); |
| 10 |
return name; |
| 11 |
} |
| 12 |
|
| 13 |
Reflection.prototype.getMethod = function(name) { |
| 14 |
for (var p in this.obj) { |
| 15 |
if (p == name && typeof(this.obj[p]) == "function") return this.obj[p]; |
| 16 |
} |
| 17 |
return null; |
| 18 |
} |
| 19 |
|
| 20 |
Reflection.prototype.getParameterNames = function() { |
| 21 |
var src = this.obj.toSource(); |
| 22 |
src = src.substring( |
| 23 |
src.indexOf("(", 8)+1, src.indexOf(")") |
| 24 |
); |
| 25 |
return src.split(/, ?/); |
| 26 |
} |