Discord
Login
Community
DARK THEME

Can't access JS function from MS

Hey, I was using Microscript to call a javascript function I made in a separate file with the proper "//javascript" heading but it says the Javascript function I made isn't a function, and could not be called.

Did they remove this functionality, or is there a different way to do it now?

I think you need to put the function into global for microscript to have access. Here are two possible approaches to fixing this issue:


// javascript

global.myFunction = function() {
  // code ...
}

I personally prefer this solution because the myFunction will only belong in the microscript's global scope. If you need to call it from javascript, you could just write global.myFunction();.


// javascript

function myFunction() {
  // code ...
}

global.myFunction = myFunction;

This also works as efficiently, but is less clean in my opinion because in the perspective of javascript, the function will be stored in both the global scope, and the global object (or whatever that is).

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community