"use strict";

// Singleton design pattern
(function() {
    console.log('-------------------------Example on singleton-------------------------');
    var Sun = (function() {
        var sunInstance;

        function createInstance() {
            return {
                shine: function shine() {
                    console.log('Sun is shining ...');
                }
            };
        }

        return {
            getInstance: function getInstance() {
                if (!sunInstance) {
                    sunInstance = createInstance();
                }
                return sunInstance;
            }
        };
    })();

    var sun = Sun.getInstance();
    var anotherSun = Sun.getInstance();
    console.log('Are there two suns: ' + (sun !== anotherSun));
    sun.shine();
})();

@@ -244,32 +244,65 @@
        return %7B%0A
+                shiningCount: 0,%0A
                 
@@ -316,22 +316,16 @@
 function
- shine
 () %7B%0A   
@@ -372,24 +372,176 @@
 ning ...');%0A
+                    this.shiningCount++;%0A                %7D,%0A                getShiningCount: function() %7B%0A                    return this.shiningCount;%0A
             
@@ -954,16 +954,16 @@
 rSun));%0A
-
     sun.
@@ -971,14 +971,1115 @@
 hine();%0A
+    sun.shine();%0A    console.log('Count in the other sun: ' + anotherSun.getShiningCount());%0A%7D)();%0A%0A// Singleton by overriding new operator%0A(function() %7B%0A    console.log('-------------------------Example on singleton by overriding new-------------------------');%0A    var Sun = (function() %7B%0A        var sunInstance;%0A%0A        function createInstance() %7B%0A            return %7B%0A                shiningCount: 0,%0A                shine: function() %7B%0A                    console.log('Sun is shining ...');%0A                    this.shiningCount++;%0A                %7D,%0A                getShiningCount: function() %7B%0A                    return this.shiningCount;%0A                %7D%0A            %7D;%0A        %7D%0A%0A        return function() %7B%0A            if (!sunInstance) %7B%0A                sunInstance = createInstance();%0A            %7D%0A            return sunInstance;%0A        %7D;%0A    %7D)();%0A%0A    var sun = new Sun();%0A    var anotherSun = new Sun();%0A    console.log('Are there two suns: ' + (sun !== anotherSun));%0A    sun.shine();%0A    sun.shine();%0A    console.log('Count in the other sun: ' + anotherSun.getShiningCount());%0A
 %7D)();%0A

Add sample of singleton by overriding new