raganwald / allong.es

https://leanpub.com/javascriptallongesix
484 stars 28 forks source link

How do I use a function to determine which property to get with get/getWith #17

Open chtulhu6662000 opened 10 years ago

chtulhu6662000 commented 10 years ago

For instance:

var fruits = [
  { name: 'orange', colour: 'orange' },
  { name: 'banana', colour: 'yellow' }
];
get(fruits[0], function() {
  if (whatever) {return 'colour';}
});
// Results: 'orange' or undefined

Or am I thinking about this the wrong way? Where I should instead look at using filter/filterWith to achieve something similar?

I am asking because I seem to want to do the same thing with pluck/pluckWith (ie: pluck arbitrary properties).