I have a function that is declared like this:
function Plugin(option) {
//logic here
}
$.fn.validator = Plugin
I need to extend this function with some logic so that it does something more like this:
function Plugin(option) {
if (myvariable == true)
{
//seperate logic
return;
}
//logic here
}
The trick is that I need to add that if statement into the function dynamically, the code that has the Plugin function gets updated frequently and I don't want to re-add that logic every time the file changes. As of right now I just create the whole function with all the logic and replace the old one with it. But this seems like a lot of wasted code. I was hoping there was a way to simply merge them, so I tried.
function Plugin(option) {
//logic here
}
function extendedPlugin(option) {
//seperate logic here
}
$.fn.validator = $.extend(Plugin, extendedPlugin);
//or
$.fn.extend($.fn.validator, extendedPlugin)
I've tried a couple variations of that logic at the bottom but it just returns the first function every time, is there a way to merge them since functions are technically objects aren't they? I think I may need to do something with prototypes but my understanding of them is still very limited.