forked from Sean-Bradley/Design-Patterns-In-TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.ts
More file actions
25 lines (22 loc) · 769 Bytes
/
Copy pathdocument.ts
File metadata and controls
25 lines (22 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// A sample document to be used in the Prototype example
import ProtoType from './iprototype'
export default class Document implements ProtoType {
name: string
array: [number[], number[]]
constructor(name: string, array: [number[], number[]]) {
this.name = name
this.array = array
}
clone(mode: number): Document {
' This clone method uses different copy techniques '
let array
if (mode === 2) {
// results in a deep copy of the Document
array = JSON.parse(JSON.stringify(this.array))
} else {
// default, results in a shallow copy of the Document
array = Object.assign([], this.array)
}
return new Document(this.name, array)
}
}