Do not execute duplicate functions in Javascript, possible?

0

I am trying to block the repetition of the execution of several functions that have the same name and basically, they are cloned.

This is not for a web, but it would be something easy to control, the issue is that each module that I draw on a page that is html, has its divs with its classes, functions, and ... as if it were an iframe, but between them they can 'read' what the other has.

So I need to isolate in some way that each module does not interact with others despite being identical.

I know it's hard to understand, but would there be any way? To check if there are for example three functions with the same name, to prevent it from being executed three times and only one?.

A thousand thanks!.

    
asked by djohny 07.11.2016 в 15:50
source

1 answer

2

One practice that has helped me a lot in cases like these, is to give each module a name and start the names of the functions as Main, with the name of the module, for example, if I put "calendar", I give it as a name to my function == > calendarMain (), so it does not conflict with other functions you have created because I will never put a module like a previous one. Another slightly more advanced process that you can do is to centralize everything in an object, all the functions and so on, so that you add it to the beginning and in the same way, it will not be in conflict. A convention for this type of object is for the name to be capitalized. An example of this is the javascript template engine called Handlebars.

    
answered by 16.11.2016 в 05:00