I don't know if you need to see the full code, but I have seen a few plugins that do this:
window.dataValidate = dataValidate
Does this add 'dataValidate' to the window object, or how does it work?
Does this add 'dataValidate' to the window object
Yes, it will.
For example, if you're inside another scope;
function foo() {
var bar = 4;
window.bar = bar;
}
You've now made bar global, and can access it from anywhere. Without the window.bar = bar, you'd only have been able to access it within foo().
You'll commonly see this being used at the end of an IIFE, to publish work to the rest of the world (e.g. jQuery);
(function () {
var jQuery;
// Setup jQuery
window.jQuery = jQuery;
}());
You might see people doing this instead;
function foo() {
bar = 4; // Note the lack of `var`
}
This has the same effect through the use of "implied globals"; but it will throw an error in ES5 strict mode, and is generally considered a bad practice (did the programmer mean to make it global, or did they simply accidentally omit var?).
window in the end you have easy control over what you actually export (= make global), plus you can easily change the way you are making it global (renaming, putting it into a different namespace, …).
dataValidateto a global variable with the same name.