SHARE
TWEET

id.js

a guest Apr 12th, 2018 330 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*======================================================================*\
  2.   ICBIaW50OiBtYWtlIHRoaXMgYXMgY2xvc2UgdG8gcHJvZHVjdGlvbi1yZWFkeSBzb3VyY2
  3.   UgY29kZSBhcyB5b3UgY2FuIQoKICBCb251cyBwb2ludHMgZm9yIHRlbGxpbmcgdXMgd2hh
  4.   dCB0aGlzIGRvZXMgaW4gcGxhaW4gdGVybXM6CgogICAgJycuam9pbihpdGVydG9vbHMuY2
  5.   hhaW4oKnppcChzWy0yOjotMl0sIHNbOjotMl0pKSk=
  6. \*======================================================================*/
  7.  
  8. if (NAMESPACE == null
  9.         || typeof (NAMESPACE) == 'undefined') {
  10.     NAMESPACE = {};
  11.  
  12.     // Creates an object that allocates a new or references an
  13.     // existing very expensive resource associated with `id`
  14.     var resource = function (id) {
  15.         // Private data
  16.         var _all_ids = new Array();
  17.         var _closed = false;
  18.         var _id = id;
  19.         var _expensive_resource = null;
  20.  
  21.         // Public data
  22.         var persona = {
  23.         };
  24.  
  25.         // Public methods
  26.         var getExpensiveResource = function () {
  27.             return _expensive_resource;
  28.         }
  29.        
  30.         persona.getExpensiveResource = getExpensiveResource;
  31.  
  32.         var getId = function () {
  33.             return _id;
  34.         }
  35.        
  36.         persona.getId = getId;
  37.  
  38.         var close = function () {
  39.             delete _all_ids[_id];
  40.             this._closed = true;
  41.         }
  42.  
  43.         persona.close = close;
  44.        
  45.         // Private methods
  46.         function _lookupOrCreateExpensiveResourceById(id) {
  47.             _expensive_resource = _all_ids[id];
  48.            
  49.             if (_expensive_resource == null) {
  50.                 // Just pretend for the sake of this example
  51.                 _expensive_resource = {
  52.                     value: "I'm a very expensive resource associated with ID " + id
  53.                 };
  54.  
  55.                 _all_ids[id] = _expensive_resource;
  56.             }
  57.            
  58.             return _expensive_resource;
  59.         }
  60.        
  61.         // Initialization
  62.         _expensive_resource = _lookupOrCreateExpensiveResourceById(id);
  63.        
  64.         return persona;
  65.     }
  66.  
  67.     NAMESPACE.resource = resource;
  68. }
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