* Get an object property based on "path" (namespace) supplied traversing the object * ... tree as necessary. * @param object {Object} An object where the properties specified might exist. * @param path {String} A string representing the property to be searched for, e.g. "user.study.series.t
(object, path)
| 50 | * @return {Any} The value of the property if found. By default, returns the special type "undefined". |
| 51 | */ |
| 52 | static get(object, path) { |
| 53 | let found, // undefined by default |
| 54 | components = ObjectPath.getPathComponents(path), |
| 55 | length = components !== null ? components.length : 0; |
| 56 | |
| 57 | if (length > 0 && ObjectPath.isValidObject(object)) { |
| 58 | let i = 0, |
| 59 | last = length - 1, |
| 60 | currentObject = object; |
| 61 | |
| 62 | while (i < last) { |
| 63 | let field = components[i]; |
| 64 | |
| 65 | const isValid = ObjectPath.isValidObject(currentObject[field]); |
| 66 | if (field in currentObject && isValid) { |
| 67 | currentObject = currentObject[field]; |
| 68 | i++; |
| 69 | } else { |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (i === last && components[last] in currentObject) { |
| 75 | found = currentObject[components[last]]; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return found; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Check if the supplied argument is a real JavaScript Object instance. |