by

Simple JS Dictionary data structure

look it up chuck!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/182763/Simple-JS-Dictionary-data-structure?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// dictionary structure function Diktionary(startValues) { this.values = startValues || {}; } Diktionary.prototype.store = function(name, value) { this.values[name] = value; }; Diktionary.prototype.lookup = function(name) { return this.values[name]; }; Diktionary.prototype.contains = function(name) { return (Object.prototype.hasOwnProperty.call(this.values, name) && Object.prototype.propertyIsEnumerable.call(this.values, name)); }; Diktionary.prototype.each = function(action) { forEachIn(this.values, action); }; function forEachIn(object, action) { try { for (var property in object) { if (Object.prototype.hasOwnProperty.call(object, property)) { action(property, object[property]); } } } catch (e) { if (e != Break) { throw e; } } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus