daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Aug 11th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private var inside Javascript literal object
  2. var foo = {
  3.  
  4.     self: null,
  5.  
  6.     init: function() {
  7.         self = this;
  8.         self.doStuff();
  9.     },
  10.  
  11.     doStuff: function() {
  12.         //stuff here
  13.     }
  14.  
  15. }
  16.    
  17. var foo = (function() {
  18.   var self = null
  19.   return {
  20.     init: ...,
  21.     doStuff: ...
  22.   };
  23. })();
  24.    
  25. init: function() {
  26.   this.self = this;
  27.   this.self.doStuff();
  28. },
  29.    
  30. var foo = function() {
  31.     var self = null;
  32.  
  33.     return {
  34.       init: function() {
  35.         self = this;
  36.         self.doStuff();
  37.       },
  38.  
  39.       doStuff: function() {
  40.         //stuff here
  41.       }
  42.     };
  43. }();
  44.    
  45. var foo = {
  46.  
  47.   self: null,
  48.  
  49.   init: function() {
  50.     this.self = this;
  51.     this.self.doStuff();
  52.   },
  53.  
  54.   doStuff: function() {
  55.     //stuff here
  56.   }
  57.  
  58. }
  59.    
  60. var foo = (function(){
  61.  
  62.   var self = null;
  63.  
  64.   return {
  65.  
  66.     init: function() {
  67.       self = this;
  68.       self.doStuff();
  69.     },
  70.  
  71.     doStuff: function() {
  72.       //stuff here
  73.     }
  74.   };
  75.  
  76. }());
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top