Created
April 29, 2013 20:25
-
-
Save nadako/5484498 to your computer and use it in GitHub Desktop.
Why, neko?
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
-cp . | |
-main Main | |
-x Main.n |
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
class Main | |
{ | |
private static function main() | |
{ | |
function newEmptyHandler():Void->Void | |
{ | |
return function():Void {}; | |
} | |
var a:Void->Void = newEmptyHandler(); | |
var b:Void->Void = newEmptyHandler(); | |
trace(a); | |
trace(b); | |
trace(a == b); | |
trace(Reflect.compareMethods(a, b)); | |
} | |
} |
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
Main.hx:12: #function:0 | |
Main.hx:13: #function:0 | |
Main.hx:14: true | |
Main.hx:15: true |
After some research, I found out that it depends on whether function holds any context from outer scope:
class Main
{
private static function newHandlerWithContext()
{
var ctx = "something";
return function() { ctx; };
}
private static function newHandlerWithoutContext()
{
return function() { };
}
private static function main()
{
var a = newHandlerWithContext();
var b = newHandlerWithContext();
trace(a == b);
trace(Reflect.compareMethods(a, b));
var a = newHandlerWithoutContext();
var b = newHandlerWithoutContext();
trace(a == b);
trace(Reflect.compareMethods(a, b));
}
}
Output:
Main.hx:18: false
Main.hx:19: false
Main.hx:23: true
Main.hx:24: true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's even more confusing, this works as expected:
class Main
{
private static function main()
{
var a:Void->Void = function():Void {};
var b:Void->Void = function():Void {};
trace(a);
trace(b);
trace(a == b);
trace(Reflect.compareMethods(a, b));
}
}
Output:
Main.hx:7: #function:0
Main.hx:8: #function:0
Main.hx:9: false
Main.hx:10: false