Closed suntong closed 6 years ago
Hey, sorry for the delay on responding... I'm a bit hazy on what you want to actually achieve... You might have more luck asking this question over in the GopherJS slack channel.
To emit console.log("foo")
with GopherJS you'd do something like js.Global.Get("console").Call("log", "foo")
... You can see similar examples in the Interacting with the DOM section of the GopherJS documentation.
As far as using GopherJS JS code in a non-GopherJS application, this may be tricky. I've not done this myself, so I'm not an expert. You can check out the Providing library functions for use in other JavaScript code section in the GopherJS documentation. I think that will allow you to define a global JS object that can contain functions that you'll be able to call from JS.
I hope this answers your questions...
NP. Thanks for your detailed answer . I'll close this and ask in GopherJS slack channel instead. Thx!
Hi Dave,
A noob question -- How to adapt
jsgo
transpiled code for/to use within console?Let me explain with a simple example: https://github.com/suntong/game24/blob/c8000136ce33497ff32d09e9d52fb33df6bb2399/str/game24/main.go#L19-L22
Suppose I've got what I want from line 20, and I'll change line 21 to
console.log(r)
,how can I write a
index.js
file that does the above two simple steps?My ultimate goal is to use my
jsgo
transpiled code as lib for my console based nodejs program. I.e., I don't know JS enough to turn the code ofto nodejs based program that use
module.exports
andrequire("./something");
for module importing.THX a lot!