In this simplistic example:
var myFunction = function(obj) {
console.log($(obj));
}
I am using the $. If I use:
jQuery.noConflict();
var myObj = {X:1};
myFunction(myObj);
Then the $ is no longer valid.
But if I wrap myFunction inside of
jQuery(function($) {
var myFunction = function(obj) {
console.log($(obj));
}
});
Then it’s no longer found. myFunction is in a separate script, so I can’t wrap everything in one gigantic jQuery(function($) {}.
Try this:
Seperate file:
The difference is that your code is executed immediately not after the dom is ready and you are placing the function in the global context (window.) so it will be available everywhere.
I don’t know what it is your doing, but in this case you may find a JQuery plugin suits you better:
Seperate file:
Of course, $( {X:1} ) might do strange things with JQuery – I’ve never tried it before!