cldrjs icon indicating copy to clipboard operation
cldrjs copied to clipboard

Clone returned .get() data?

Open rxaviers opened this issue 11 years ago • 2 comments

The returned data from .get() or any of its aliased functions (eg. .main()) return the original data from the internal resolved/unresolved tree. It means that if the returned data is not a leaf, but an object; and caller function changes it, it will get permanently changed and it will affect further calls.

Should we return a clone instead? util/json/merge could be used to perform the clone and we could offer an option to bypass cloning if the caller needs full performance and knows what he's doing.

rxaviers avatar May 20 '14 05:05 rxaviers

IMO, doing a deep clone of the returned data is the right thing to do. The ability of another library to modify the internal data structures of an instance of Cldr would be potentially hazardous.

bryanforbes avatar Jun 09 '15 14:06 bryanforbes

:+1:

rxaviers avatar Jun 09 '15 14:06 rxaviers