diff options
| author | Misko Hevery | 2011-04-12 16:15:05 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2011-06-08 15:01:32 -0700 | 
| commit | bb67ee8d28f2cddb4b503dc8909649994a4d67e1 (patch) | |
| tree | 3abc82d98d29aee7abfd197e3d6d5c897f375804 /src | |
| parent | 2a12f7dcaa078e1d6c3b5092e62dd5f404b8c3e4 (diff) | |
| download | angular.js-bb67ee8d28f2cddb4b503dc8909649994a4d67e1.tar.bz2 | |
Added HashMap
Diffstat (limited to 'src')
| -rw-r--r-- | src/apis.js | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/src/apis.js b/src/apis.js index 237a1c1c..11fa9838 100644 --- a/src/apis.js +++ b/src/apis.js @@ -807,6 +807,39 @@ var angularFunction = {    }  }; +function hashKey(obj) { +  var objType = typeof obj; +  var key = obj; +  if (objType == 'object') { +    if (typeof (key = obj.$hashKey) == 'function') { +      // must invoke on object to keep the right this +      key = obj.$hashKey(); +    } else if (key === undefined) { +      key = obj.$hashKey = nextUid(); +    } +  }; +  return objType + ':' + key; +} + +function HashMap(){} +HashMap.prototype = { +  put: function(key, value) { +    var _key = hashKey(key); +    var oldValue = this[_key]; +    this[_key] = value; +    return oldValue; +  }, +  get: function(key) { +    return this[hashKey(key)]; +  }, +  remove: function(key) { +    var _key = hashKey(key); +    var value = this[_key]; +    delete this[_key]; +    return value; +  } +}; +  function defineApi(dst, chain){    angular[dst] = angular[dst] || {};    forEach(chain, function(parent){ @@ -819,6 +852,8 @@ defineApi('Array', [angularGlobal, angularCollection, angularArray]);  defineApi('Object', [angularGlobal, angularCollection, angularObject]);  defineApi('String', [angularGlobal, angularString]);  defineApi('Date', [angularGlobal, angularDate]); +// TODO: enable and document this API +//defineApi('HashMap', [HashMap]);  //IE bug  angular['Date']['toString'] = angularDate['toString'];  defineApi('Function', [angularGlobal, angularCollection, angularFunction]); | 
