Skip to content

The Problem of Object Exports in Large JavaScript Codebases #489

Closed Answered by zollqir
JoeanAmier asked this question in Q&A
Discussion options

You must be logged in to vote

There are many ways to do this. If you want to do this in a single file, the simplest would be to put those functions in a container, like a list or object.

import pythonmonkey as pm

function_object = pm.eval("""() => {
  function a(str) {
    return b(str);
  }
  function b(str) {
    return c(str);
  }
  function c(str) {
    return str;
  }
  
  return {a, b, c};
}""")()
print(function_object.a("1751802131000"))
print(function_object.b("1751802131000"))
print(function_object.c("1751802131000"))

Alternatively, if you're willing to use multiple files, you can make a CommonJS module that you export the functions from.

definitions.js:

function a(str) {
  return b(str);
}
function b(str) {
  

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JoeanAmier
Comment options

Answer selected by zollqir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants