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 https://github.com/henrikra/portfolio-flex/blob/master/assets/scripts/main.js

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: https://github.com/henrikra/portfolio-flex/commit/8ad79d235f31eb8e1d70f17663988af15a3689f2
What is your approach? :slight_smile:

2 Likes

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