function - Understanding singleton object in Javascript -
i'm having trouble understanding happens when instance calls new universe(). doesn't return "undefined"?
function universe() { var instance; universe = function universe() { return instance; } universe.prototype = this; instance = new universe(); instance.constructor = universe; instance.start_time = 0; instance.bang = "big"; return instance; }
it wont return undefined instead of return object.see in alert box or in console;
function universe() { var instance; universe = function universe() { return instance; } universe.prototype = this; instance = new universe(); alert("ins"+instance);//or console.log(instance); instance.constructor = universe; instance.start_time = 0; instance.bang = "big"; return instance; } alert(universe());//or console.log(universe());
Comments
Post a Comment