We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5e7fe47 + bcdad46 commit 33bdc37Copy full SHA for 33bdc37
chapters/classes_and_objects/cloning.md
@@ -14,6 +14,17 @@ clone = (obj) ->
14
if not obj? or typeof obj isnt 'object'
15
return obj
16
17
+ if obj instanceof Date
18
+ return new Date(obj.getTime())
19
+
20
+ if obj instanceof RegExp
21
+ flags = ''
22
+ flags += 'g' if obj.global?
23
+ flags += 'i' if obj.ignoreCase?
24
+ flags += 'm' if obj.multiline?
25
+ flags += 'y' if obj.sticky?
26
+ return new RegExp(obj.source, flags)
27
28
newInstance = new obj.constructor()
29
30
for key of obj
0 commit comments