I have the following structure
// script1.js
jQuery(document).ready(function($) {
var somevar;
$('somelem').myPlugin();
});
// script2.js
(function($) {
$.fn.myPlugin = function(options) {
// access and modify 'somevar' here so that it gets modified
// in the function which called a plugin
};
});
- I want the 'somevar' variable to get modified by plugin and I would be able to work with already modified variable further in the plugin caller function's scope.
- I do not want to use global variable.
- I see no use of passing the variable as an option to a plugin as it would become local to a plugin function and modifying would not modify the original variable as I understand.
- I may misunderstand the concept of how javascript works, so any answer appreciated.