1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["dojox.lang.functional.object"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.lang.functional.object"] = true;
dojo.provide("dojox.lang.functional.object");
dojo.require("dojox.lang.functional.lambda");
// 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).
(function(){
var d = dojo, df = dojox.lang.functional, empty = {};
d.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 || d.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 || d.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 || d.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
}
});
})();
}
|