-
-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow @:native("") with empty string #2925
Comments
This would not work, because "require" might be a user local variable, so that would easily break. |
I understand. |
There is currently no good solution, see #1492 |
Sincerely adapting the @:native("") to simply hiding the '.' would solve the problem of global functions. |
Using "native" give us freedom to do stuff like:
@:native("(require('mongodb').MongoClient)")
The resulting code will be " x = new (require('mongodb').MongoClient)(...)"
So far so good, but:
There are some global functions (like 'require' in nodejs) that do not have an object to give access to it.
It would be interesting to create a "context class" with native("") that will compile its attributes "free" of classes scope.
Something like this:
@:native("")
extern class NodeJS
{
@:native("require")
static function require(s:String):Dynamic;
}
Currently Haxe generates this JS:
.hx [ x = NodeJS.require("module"); ]
.js [ x = .require("module") ]
The "." spoils the fun. I think that the native("") could be a special case without the "."
This way things like this:
static public function require(p_lib : String):Dynamic { return untyped js("require(p_lib)"); }
Would not be necessary.
The text was updated successfully, but these errors were encountered: