Created
April 8, 2019 10:13
-
-
Save mi-mina/a727b1aa2d790c084cfd69235fd3d78d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function getOptionalProperty(obj, ...props) { | |
| const val = obj[props[0]]; | |
| if (props.length === 1 || !val) return val; | |
| const rest = props.slice(1); | |
| return getOptionalProperty.apply(null, [val, ...rest]); | |
| } | |
| const user = { name: "fluffy" }; | |
| const zip = getOptionalProperty(user, "address", "zip"); | |
| console.log("zip", zip); | |
| // From Fun fun function: https://www.youtube.com/watch?v=FKRVqtP8o48 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment