-
-
Save Tomyail/4481951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
{ | |
import flash.system.System; | |
import flash.utils.describeType; | |
public class FunctionUtils | |
{ | |
/** | |
* 不适合构造函数 | |
* @param target | |
* @param f arguments.callee | |
* @return | |
*/ | |
public static function functionToString(target:*, f:Function):String | |
{ | |
var functionName:String = "error!"; | |
var type:XML = describeType(target); | |
for each (var node:XML in type..method) | |
{ | |
if (target[node.@name] == f) | |
{ | |
functionName = node.@name; | |
break; | |
} | |
} | |
System.disposeXML(type); | |
return functionName; | |
} | |
/** | |
* debug only | |
* @param e | |
* @return | |
*/ | |
public static function getFunctionName(e:Error):String | |
{ | |
var stackTrace:String = e.getStackTrace(); // entire stack trace | |
var startIndex:int = stackTrace.indexOf("at "); // start of first line | |
var endIndex:int = stackTrace.indexOf("()"); // end of function name | |
return stackTrace.substring(startIndex + 3, endIndex); | |
} | |
public function FunctionUtils() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment