diff options
Diffstat (limited to 'src/apis.js')
| -rw-r--r-- | src/apis.js | 34 | 
1 files changed, 31 insertions, 3 deletions
| diff --git a/src/apis.js b/src/apis.js index 11fa9838..1e1bcae1 100644 --- a/src/apis.js +++ b/src/apis.js @@ -807,6 +807,16 @@ var angularFunction = {    }  }; +/** + * Computes a hash of an 'obj'. + * Hash of a: + *  string is string + *  number is number as string + *  object is either call $hashKey function on object or assign unique hashKey id. + *  + * @param obj + * @returns {String} hash string such that the same input will have the same hash string + */  function hashKey(obj) {    var objType = typeof obj;    var key = obj; @@ -821,17 +831,37 @@ function hashKey(obj) {    return objType + ':' + key;  } +/** + * HashMap which can use objects as keys + */  function HashMap(){}  HashMap.prototype = { +  /** +   * Store key value pair +   * @param key key to store can be any type +   * @param value value to store can be any type +   * @returns old value if any +   */    put: function(key, value) {      var _key = hashKey(key);      var oldValue = this[_key];      this[_key] = value;      return oldValue;    }, +   +  /** +   * @param key +   * @returns the value for the key +   */    get: function(key) {      return this[hashKey(key)];    }, +   +  /** +   * Remove the key/value pair +   * @param key +   * @returns value associated with key before it was removed +   */    remove: function(key) {      var _key = hashKey(key);      var value = this[_key]; @@ -852,8 +882,6 @@ 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']; +angular.Date.toString = angularDate.toString;  defineApi('Function', [angularGlobal, angularCollection, angularFunction]); | 
