From da11cf8f9f26f39a2f0e77fb0777c21194f91605 Mon Sep 17 00:00:00 2001 From: jettcalleja Date: Mon, 2 Oct 2017 21:54:46 +0800 Subject: [PATCH] fix: clone() cloning prototype's custom methods --- lib/winston/common.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/winston/common.js b/lib/winston/common.js index d1af9491f..fe0e1dacc 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -104,17 +104,19 @@ function clone(obj) { var copy = Array.isArray(obj) ? [] : {}; for (var i in obj) { - if (Array.isArray(obj[i])) { - copy[i] = obj[i].slice(0); - } - else if (obj[i] instanceof Buffer) { + if (obj.hasOwnProperty(i)) { + if (Array.isArray(obj[i])) { copy[i] = obj[i].slice(0); - } - else if (typeof obj[i] != 'function') { - copy[i] = obj[i] instanceof Object ? exports.clone(obj[i]) : obj[i]; - } - else if (typeof obj[i] === 'function') { - copy[i] = obj[i]; + } + else if (obj[i] instanceof Buffer) { + copy[i] = obj[i].slice(0); + } + else if (typeof obj[i] != 'function') { + copy[i] = obj[i] instanceof Object ? exports.clone(obj[i]) : obj[i]; + } + else if (typeof obj[i] === 'function') { + copy[i] = obj[i]; + } } }