Javascript: Private object with a public accessor


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if (typeof MyApp !== 'object') (function () {
  2. // Public Methods
  3. window.doPrivateMethod = function (boo) {
  4. MyApp.privateMethod(boo);
  5. }
  6. // Private Vars
  7. var MyApp = {
  8. init:function() {
  9. console.log(this);
  10. },
  11. privateMethod:function(res) {
  12. console.log('Called Private Method with ' + res);
  13. }
  14. };
  15. return MyApp.init();
  16. })();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.