JSFiddle - React, Tailwind, and code Playground

by deepak sisodiya

HTML

In JavaScript, the singleton is used mostly for namespacing and reducing the number of global variables that your application creates. This pattern is probably more useful in JavaScript than in any other language due to the high risk of using global variables in your code

JavaScript

// Singleton Patterns in javascript

var alert  = function (str) {
   var st = document.createTextNode(str);
   var p = document.createElement('p');
   p.appendChild(st);
   document.querySelector('body').appendChild(p);
}

var MYAPPLICATION = {
    firstName:function(firstName) {
        return alert(firstName)              
    },
    lastName:function(lastName) {
        return alert(lastName)              
    }
}
MYAPPLICATION.firstName("deepak");   
MYAPPLICATION.lastName("sisodiya");