diff options
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]); |
