damoebius
(david mouton)
1
Hi,
I want to make my own nodejs module.
It should looks like :
var myAwesomeModule = {
postmessage: function () {
// whatever
},
onmessage: function () {
// whatever
}
}
module.exports = myAwesomeModule;
I can’t do it in haxe.
Any idea ?
back2dos
(Juraj Kirchheim)
2
class MyAwesomeModule {
static function main() {
untyped module.exports = {
postmessage: function () {
// whatever
},
onmessage: function () {
// whatever
}
}
}
}
And build with haxe -js my-awesome-module.js -main MyAwesomeModule
. Note that this will of course entirely sabotage @:expose
1 Like
jeremyfa
(Jérémy Faivre)
3
In the same fashion, but in order to prevent the whole block expression to be untyped
, you can also do this:
var module:Dynamic = js.Node.module;
module.exports = {
postmessage: function () {
// whatever
},
onmessage: function () {
// whatever
}
};
2 Likes
elsassph
(Philippe)
4
If you don’t need to re-create the exports
object you can just add @:expose('postmessage')
on a static function.
2 Likes