| I fail to see how the following code from the book is an example of a singleton: 01 var mySingleton = function(){ 02 03 /* here are my private variables and methods / 04 var privateVariable = 'something private'; 05 function showPrivate(){ 06 console.log(privateVariable); 07 } 08 09 / public variables and methods (which can access private variables and methods ) */ 10 return { 11 publicMethod:function(){ 12 showPrivate(); 13 }, 14 publicVar:'the public can see this!' 15 } 16 } 17 18 var single = mySingleton(); Also, the code is missing semicolons. Missing semicolons is a problem when minifying the code. I would recommend running your example code through JS lint for the next edition of the book. Still, I've been looking to improve my JS foo and reading through this book may help. I will continue. It is attractively formatted and addresses topics that I want to know more about. |