Files
openlayers/src/ol/obj.js
Tim Schaub ad62739a6e Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
2018-01-12 00:50:30 -07:00

75 lines
1.8 KiB
JavaScript

/**
* @module ol/obj
*/
const _ol_obj_ = {};
/**
* Polyfill for Object.assign(). Assigns enumerable and own properties from
* one or more source objects to a target object.
*
* @see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
* @param {!Object} target The target object.
* @param {...Object} var_sources The source object(s).
* @return {!Object} The modified target object.
*/
_ol_obj_.assign = (typeof Object.assign === 'function') ? Object.assign : function(target, var_sources) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
const output = Object(target);
for (let i = 1, ii = arguments.length; i < ii; ++i) {
const source = arguments[i];
if (source !== undefined && source !== null) {
for (const key in source) {
if (source.hasOwnProperty(key)) {
output[key] = source[key];
}
}
}
}
return output;
};
/**
* Removes all properties from an object.
* @param {Object} object The object to clear.
*/
_ol_obj_.clear = function(object) {
for (const property in object) {
delete object[property];
}
};
/**
* Get an array of property values from an object.
* @param {Object<K,V>} object The object from which to get the values.
* @return {!Array<V>} The property values.
* @template K,V
*/
_ol_obj_.getValues = function(object) {
const values = [];
for (const property in object) {
values.push(object[property]);
}
return values;
};
/**
* Determine if an object has any properties.
* @param {Object} object The object to check.
* @return {boolean} The object is empty.
*/
_ol_obj_.isEmpty = function(object) {
let property;
for (property in object) {
return false;
}
return !property;
};
export default _ol_obj_;