Skip to content

Instantly share code, notes, and snippets.

@Tomyail
Forked from anonymous/FunctionUtils
Last active December 10, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomyail/4481951 to your computer and use it in GitHub Desktop.
Save Tomyail/4481951 to your computer and use it in GitHub Desktop.
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