Use Object.values if available

As `Object.values`, the arguments now can't be `null` or `undefined`.
This commit is contained in:
Frederic Junod
2018-11-17 14:50:37 +01:00
parent 06ae175cef
commit 4a3a53c725
2 changed files with 7 additions and 5 deletions

View File

@@ -44,18 +44,20 @@ export function clear(object) {
/**
* Get an array of property values from an object.
* @param {Object<K,V>} object The object from which to get the values.
* Polyfill for Object.values(). Get an array of property values from an object.
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
*
* @param {!Object<K,V>} object The object from which to get the values.
* @return {!Array<V>} The property values.
* @template K,V
*/
export function getValues(object) {
export const getValues = (typeof Object.values === 'function') ? Object.values : function(object) {
const values = [];
for (const property in object) {
values.push(object[property]);
}
return values;
}
};
/**