Last active
October 11, 2016 19:20
-
-
Save ddamko/a6d963e28b863404ff0feec5939f81df to your computer and use it in GitHub Desktop.
Trying to create a base Value Object class in TypeScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const VO = require('value-object-js'); | |
abstract class ValueObject { | |
constructor(private name: string, private value: any) { | |
const ValueObj = VO.define(name ,{ | |
validate: (value) => { return value } | |
}); | |
return new ValueObj(value); | |
} | |
} | |
class Money extends ValueObject { | |
constructor(value: number) { | |
super('Money', value); | |
} | |
} | |
let money_one = new Money(3); | |
let money_two = new Money(3); | |
console.log(money_one === money_two); // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment