1 | var Accessor = {
|
2 | IDENTITY_FN: function (input) {
|
3 | return input;
|
4 | },
|
5 |
|
6 | generateAccessor: function (field) {
|
7 | return function (object) {
|
8 | return object[field];
|
9 | };
|
10 | },
|
11 |
|
12 | generateOptionToStringFor: function (prop) {
|
13 | if (typeof prop === 'string') {
|
14 | return this.generateAccessor(prop);
|
15 | } else if (typeof prop === 'function') {
|
16 | return prop;
|
17 | } else {
|
18 | return this.IDENTITY_FN;
|
19 | }
|
20 | },
|
21 |
|
22 | valueForOption: function (option, object) {
|
23 | if (typeof option === 'string') {
|
24 | return object[option];
|
25 | } else if (typeof option === 'function') {
|
26 | return option(object);
|
27 | } else {
|
28 | return object;
|
29 | }
|
30 | }
|
31 | };
|
32 |
|
33 | module.exports = Accessor; |
\ | No newline at end of file |