I have a file with a line size of 300 lines that installs jQuery event handlers and other necessary functions for a partial view, which is used by several views in an ASP.NET MVC application. Event handlers process 99% of everything, regardless of which view uses a partial. This question is about this 1% difference.
Since JavaScript has no interfaces, is it safe to define a function that will be called by one or more event handlers that handle different things in a separate file that is loaded depending on what kind is used? If not, what would be the best way to deal with this situation? In other languages, I would use interfaces and / or abstract classes in this situation.
Example:
shared file
$(document).ready(function() {
$(document).on('click', '.selectable-table tbody tr', function() {
mySpecificFunction();
});
});
Definition1.js
function mySpecificFunction() {
}
Definition2.js
function mySpecificFunction() {
}
Views will load the relevant scripts as such:
<script src="definitionX.js"></script>
<script src="sharedScript.js"></script>
A "signature" (the term is used generously because javascript) mySpecificFunction()will be the same for each definition, but something in my gut tells me that this is bad practice. Is there a better / right way to do this or a design template for this purpose?