Created
February 5, 2015 23:34
-
-
Save mattpodwysocki/d9537f51d833d0af1e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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