Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created February 5, 2015 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/d9537f51d833d0af1e91 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/d9537f51d833d0af1e91 to your computer and use it in GitHub Desktop.
/**
* Retrieves the value of a specified nested property from all elements in
* the Observable sequence.
* @param {Arguments} arguments The nested properties to pluck.
* @returns {Observable} Returns a new Observable sequence of property values.
*/
observableProto.pluck = function () {
var args = arguments, len = arguments.length;
if (len === 0) { throw new Error('List of properties cannot be empty.'); }
return this.map(function (x) {
var currentProp = x;
for (var i = 0; i < len; i++) {
var p = currentProp[args[i]];
if (typeof p !== 'undefined') {
currentProp = p;
} else {
return undefined;
}
}
return currentProp;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment