Skip to content

Commit

Permalink
Added clone method to Data class
Browse files Browse the repository at this point in the history
  • Loading branch information
profexorgeek committed Jan 4, 2022
1 parent c047bd7 commit 3dcbcf2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Data {
const promiseImage = new Image();
promiseImage.addEventListener('load', () => resolve(promiseImage));
promiseImage.addEventListener('error', (err) => {
FrostFlake.Log.error(`Error loading ${src}...`);
FrostFlake.Log.error(`Error loading ${src}...\n${err}`);
reject(err)
});
promiseImage.src = src;
Expand Down Expand Up @@ -87,4 +87,13 @@ export default class Data {
return null;
}
}

static clone(obj: any): any {
// converting to and from JSON is a simple
// way to fully clone an object as a new
// reference
let json = JSON.stringify(obj);
let copy = JSON.parse(json);
return copy;
}
}

0 comments on commit 3dcbcf2

Please sign in to comment.