Based on your comment, it sounds like that is the actual code you have and not a paraphrased version of it, so that's just some bogus code.
- You can create a variable and assign a value to it without using
var and it will be treated as a global variable, but this is considered a bad practice and forbidden in strict mode.
- The first statement is an IIFE, but it doesn't return anything, so
MyObject is undefined. So when new MyObject(); eventually runs, it will just throw an error and halt the execution of the ready handler.
It looks like the person who wrote that code may have been trying to do this, but was making an attempt to be clever:
var MyObject = function() {
alert("Object created");
};
$(function() {
new MyObject();
});
Here, MyObject is a function that shows an alert. The jQuery ready handler invokes that function as a constructor, which causes the code inside the function to run (showing an alert), and creating a new object. However, this object is not used or assigned anywhere, so it just gets garbage collected after some period of time.
MyObjectisundefinedafter that first statement.