Skip to content

Instantly share code, notes, and snippets.

@CezaryDanielNowak
Last active January 18, 2022 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CezaryDanielNowak/c2d398758564374f2837679a10309997 to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/c2d398758564374f2837679a10309997 to your computer and use it in GitHub Desktop.
/*
* Some JS objects like InputDeviceInfo or GeolocationCoordinates are impossible to clone easly.
* `Object.keys(obj)` returns `{}`
* `JSON.stringify(obj)` returns `{}`
*
* with following functions you're able to clone object properties to the simple object.
*/
function cloneGeolocationCoordinates(instance) {
return Object.keys(instance.constructor.prototype).reduce((acc, key) => {
acc[key] = instance[key];
return acc;
}, {});
}
function cloneInputDeviceInfo(instance) {
const result = Object.keys(MediaDeviceInfo.prototype).reduce((acc, key) => {
acc[key] = instance[key];
return acc;
}, {});
delete result.toJSON;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment