mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-10 02:03:07 +08:00
fix(util): Utils.deepClone properly clones dates
This commit is contained in:
parent
a9d0f3f56a
commit
aca3363e3c
2 changed files with 9 additions and 0 deletions
|
@ -76,6 +76,11 @@ describe 'Utils', ->
|
|||
@o2.circular = @o2
|
||||
@o2Clone = Utils.deepClone(@o2)
|
||||
|
||||
it "deep clones dates correctly", ->
|
||||
d1 = new Date(2016,1,1)
|
||||
d2 = Utils.deepClone(d1)
|
||||
expect(d2.valueOf()).toBe(d1.valueOf())
|
||||
|
||||
it "makes a deep clone", ->
|
||||
@v1.push(4)
|
||||
@v2.push(7)
|
||||
|
|
|
@ -81,6 +81,10 @@ Utils =
|
|||
if _.isArray(object)
|
||||
# http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
|
||||
newObject = []
|
||||
else if object instanceof Date
|
||||
# You can't clone dates by iterating through `getOwnPropertyNames`
|
||||
# of the Date object. We need to special-case Dates.
|
||||
newObject = new Date(object)
|
||||
else
|
||||
newObject = Object.create(Object.getPrototypeOf(object))
|
||||
|
||||
|
|
Loading…
Reference in a new issue