prototype design pattern typescript

The solution for “prototype design pattern typescript” can be found here. The following code will assist you in solving the problem.

interface IPrototype {
getClone(): InstanceType
}

class Person implements IPrototype {
public name: string
public age: number
public hobby: string

constructor(name: string, age: number, hobby: string) {
this.name = name
this.age = age
this.hobby = hobby
}

public getClone(): InstanceType {
return this
}
}

const john: Person = new Person(‘john doe’, 30, ‘programming’)
console.log(john)

const jane = john.getClone()
jane.name = ‘jane doe’
jane.hobby = ‘swimming’

console.log(jane)

const ari = john.getClone()
ari.name = ‘ari gunawan’
ari.age = 25
ari.hobby = ‘music’

console.log(ari)

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in