[英]How to detect caller in haxe?
I am setting a property, I need to know who is setting the property value? 我正在设置一个属性,我需要知道谁设置了属性值? is this possible in haxe 3?
haxe 3有可能吗?
Also, can I know who is calling a function from inside the function itself? 另外,我可以知道谁在函数内部调用函数吗?
Check out PosInfos . 看看PosInfos 。 You use it like so:
你这样使用它:
public static function add(a:Int, b:Int, ?pos:PosInfos) {
trace( 'Called from ${pos.className}');
trace( 'Called from ${pos.methodName}');
trace( 'Called from ${pos.fileName}');
trace( 'Called from ${pos.lineNumber}');
return a+b;
}
add( 1, 1 ); // "pos" will automatically be filled in by compiler
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.