Best way to separate JS functions?

Im doing new project with Sage and my js it getting pretty big now. You can see my file here

Is there way to separate them to different files? How do you guys organize js in your sage projects? :slightly_smiling:

1 Like

Well it seems like you’ve added less than 100 lines, I personally wouldn’t quite call that unwieldy quite yet.

But since you’ve created quite a few functions, you could extract those to their own file and keep main.js pretty lean. You’d just have to make sure you are passing all variables or objects you’re using as references, as moving them to a separate file will change their scope.

1 Like

Thanks you for the info. Is it possible for you to show how can I achieve this? :slight_smile:

Give it a shot. If you can’t figure it out, explain in detail what you tried to do to get it working.

I made this kind of solution:
What is your approach? :slight_smile:


I ended up doing something like this. It’s not super clean, but works ok for now. I plan to refactor it when jumping to Sage 9