diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.7.2/dojox/lang/functional/object.js | |
Diffstat (limited to 'js/dojo-1.7.2/dojox/lang/functional/object.js')
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/functional/object.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/js/dojo-1.7.2/dojox/lang/functional/object.js b/js/dojo-1.7.2/dojox/lang/functional/object.js new file mode 100644 index 0000000..c35ef4f --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/functional/object.js @@ -0,0 +1,77 @@ +//>>built +define("dojox/lang/functional/object", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/window", "./lambda"], function(dojo, lang, win, df){ + +// This module adds high-level functions and related constructs: +// - object/dictionary helpers + +// Defined methods: +// - take any valid lambda argument as the functional argument +// - skip all attributes that are present in the empty object +// (IE and/or 3rd-party libraries). + + var empty = {}; + +/*===== + var df = dojox.lang.functional; + =====*/ + lang.mixin(df, { + // object helpers + keys: function(/*Object*/ obj){ + // summary: returns an array of all keys in the object + var t = []; + for(var i in obj){ + if(!(i in empty)){ + t.push(i); + } + } + return t; // Array + }, + values: function(/*Object*/ obj){ + // summary: returns an array of all values in the object + var t = []; + for(var i in obj){ + if(!(i in empty)){ + t.push(obj[i]); + } + } + return t; // Array + }, + filterIn: function(/*Object*/ obj, /*Function|String|Array*/ f, /*Object?*/ o){ + // summary: creates new object with all attributes that pass the test + // implemented by the provided function. + o = o || win.global; f = df.lambda(f); + var t = {}, v, i; + for(i in obj){ + if(!(i in empty)){ + v = obj[i]; + if(f.call(o, v, i, obj)){ t[i] = v; } + } + } + return t; // Object + }, + forIn: function(/*Object*/ obj, /*Function|String|Array*/ f, /*Object?*/ o){ + // summary: iterates over all object attributes. + o = o || win.global; f = df.lambda(f); + for(var i in obj){ + if(!(i in empty)){ + f.call(o, obj[i], i, obj); + } + } + return o; // Object + }, + mapIn: function(/*Object*/ obj, /*Function|String|Array*/ f, /*Object?*/ o){ + // summary: creates new object with the results of calling + // a provided function on every attribute in this object. + o = o || win.global; f = df.lambda(f); + var t = {}, i; + for(i in obj){ + if(!(i in empty)){ + t[i] = f.call(o, obj[i], i, obj); + } + } + return t; // Object + } + }); + + return df; +}); |
