Skip to content

Commit

Permalink
Check if a property exists in the original object
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsgames committed Sep 21, 2021
1 parent 8f1f269 commit 90938c5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function klona(x) {
if (x.constructor !== Object && typeof x.constructor === 'function') {
tmp = new x.constructor();
for (k in x) {
if (tmp[k] !== x[k]) {
if (x.hasOwnProperty(k) && tmp[k] !== x[k]) {
tmp[k] = klona(x[k]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function klona(x) {
if (x.constructor !== Object && typeof x.constructor === 'function') {
tmp = new x.constructor();
for (k in x) {
if (tmp[k] !== x[k]) {
if (x.hasOwnProperty(k) && tmp[k] !== x[k]) {
tmp[k] = klona(x[k]);
}
}
Expand Down

0 comments on commit 90938c5

Please sign in to comment.