I’m building my first site based on backbone.js and I have a bit of a semantics question.
My JS app is structured like so:
application.js
/collections/WorkspaceCollection.js
...buch of other more atomic collections
/views/WorkspaceView.js
...buch of other more atomic views
/controllers/WorkspaceController.js (extends router)
...bunch of other atomic controllers
/models/WorkspaceModel.js
...bunch of other atomic models
in my application.js file i instantiate the Worksapce and it goes about it’s business fine.
My question is that if I have a load of sortof… no.. MVC based functions which I need to perform sometimes lets say like a buch of math functions used in various places.
Is it more correct to simply dump these into the application.js or should I look to extend the global Math object (that seems a bit cleaner but hmmm)
guess I’m looking for hygiene tips 🙂
[Edit]:
Just to avoid any confusions, I have a bunch of math functions which I need to do some vector maths as well as a few things which javascript doesnt inherently have in it’s own Math class.
I use some of these in different places throughout the app.
Incidentally, this question could I guess apply if I had a load of string, audio video etc functions too.
I am having a bit or trouble understanding what you are asking here…
But math functions feel like they should be part of your model. The model isn’t just a bunch of data objects. It includes business rules that are important to you application. It models your world which often includes math. The view doesn’t usually care as much about math unless you are doing some more native drawing or animation…
If the math functions in question are generic, then maybe you just need a math utility function? I mean, you CAN extend the Math object but why risk polluting that space? If you don’t want it in your model then make your own math utility.