In the below code
(function x() {
var j = function() { alert("234234"); }
return {
s: j
}
})()
var x1 = new x();
x1.s();
How to invoke the method j()? Or before that i should be asking, is there a way to create an instance of the function x() because that is what is happening. Please see the fiddle http://jsfiddle.net/e5k6bdvn/
new
)Such:
var x = (function () {
var j = function() { alert("234234"); };
return {
s: j
};
})();
x.s();
Or, if you want to create multiple objects in the same way:
x
as many times as you likeSuch:
function x () {
var j = function() { alert("234234"); };
return {
s: j
};
};
var x1 = x();
var x2 = x();
x1.s();
Or, if you want to create a constructor function:
Such:
function x () {
};
x.prototype.s = function () {
alert("234234");
}
var x1 = new x();
var x2 = new x();
x1.s();