class Word {
constructor(
public term: string,
public def: string) {}
}
const kimchi = new Word('kimchi', '한국음식');
console.log(kimchi);
"use strict";
class Word {
constructor(term, def) {
this.term = term;
this.def = def;
}
}
type Words = {
[key: string]: string;
};
class Dict {
private words: Words;
constructor() {
this.words = {};
}
add(word: Word) {
if (this.words[word.term] === undefined) {
this.words[word.term] = word.def;
}
}
def(term: string) {
return this.words[term];
}
}
const myDic = new Dict();
console.log(myDic);
myDic.add(kimchi);
console.log(myDic);
console.log(myDic.def('kimchi'));