Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

prototype design pattern typescript

interface IPrototype {
	getClone(): InstanceType<typeof Person>
}

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<typeof Person> {
		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)
Comment

prototype design pattern typescript

interface IPrototype {
	getClone(): InstanceType<typeof Person>
}

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<typeof Person> {
		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)
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript type specific strings 
Typescript :: typescript get objects nested in object 
Typescript :: paragraph dots after 2 lines css 
Typescript :: chakra ui menu open on hover 
Typescript :: cypress with typescript 
Typescript :: ts date get minutes 
Typescript :: download toasts in django 
Typescript :: multer nestjs 
Typescript :: typescript string 
Typescript :: 2 positional arguments but 3 were given 
Typescript :: __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ 
Typescript :: git merge all previous commits on a branch 
Typescript :: python remove accents pandas 
Typescript :: ts factory pattern 
Typescript :: typeorm configuration typescript 
Typescript :: react typescript append to array 
Typescript :: servlets meaning 
Typescript :: typescript annotate return type 
Typescript :: typescript wrapping for array 
Typescript :: bootstrap get elements id 
Typescript :: Custom Error Message Class 
Typescript :: typescript `is a` function determine type 
Typescript :: localhost magento 2 installation redirects to the live server 
Typescript :: typescript -g doesnst read tsconfog 
Typescript :: permalink of pending posts not working 
Typescript :: nextjs waiting for compiling problem 
Typescript :: get ols regression results with for loop for dataframe against a constant 
Typescript :: how many straight and curves are there in a standard track 
Typescript :: how to ignore a field while desiarilizing in java if its type is not wrong 
Typescript :: stats splunk many fields 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =