const utils = (function () { let instance; function initialize() { return { sum: function (a, b) { return a + b; } }; } return { getInstance: function () { if (!instance) { instance = initialize(); } return instance; } }; })(); let sum = utils.getInstance().sum(3, 5); // 8
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter