Reputation: 1029
I want to know differences between the two following approaches from efficiency or any other point of views:(these codes are written using HTML5 Canvas)
first one has separate functions including drawScreen() function and event handling functions which all call the drawScreen().
the other one has a function canvasApp() which contains all the functions including drawScreen() inside along with other functions for handling the events. these function again call the drawScreen function inside themselves.
the codes are so long but if the explanation is not clear enough I will put the codes.
Upvotes: 2
Views: 69
Reputation: 69663
This is a rather religious question.
Javascript is a programming language which combines concepts from procedural, functional and object-oriented programming, so it allows to work in a lot of different programming paradigms.
Option one would be the procedural approach, while two would be the object-oriented approach. We could now have an endless discussion about which programming paradigm is the best, but we would never come to a result.
You have to know for yourself which programming style suits you best and suits your application best.
Upvotes: 2
Reputation: 25204
It sounds like you either want to have one function that takes a parameter which indicates which function to call, or you want to simply call each function directly. Please correct me if I am wrong.
I would personally go with the separate options. I don't see what encapsulating them inside a global function would bring in terms of functionality or simplicity. As long as the functions are clearly defined and documented I believe this is probably the best approach.
I would be more than happy to give you a more detailed answer, but you are going to have to enlighten us a bit more on your overall architecture (maybe with some pseudocode).
Upvotes: 2