Last active
May 9, 2020 14:50
-
-
Save CagriAldemir/0e8249ca313eb7ec3f42d9df464ac642 to your computer and use it in GitHub Desktop.
This file contains 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
export class DemoClass { | |
public foo: string; | |
public bar: string; | |
public fooLabel: string; | |
public barLabel: string; | |
toJSON() { | |
return { | |
foo: this.foo, | |
bar: this.bar, | |
}; | |
} | |
} |
This file contains 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
export class TempVariableInserter { | |
constructor() {} | |
addTempVariable(key: string, value: any) { | |
Object.defineProperty(this, key, { | |
value: value, | |
writable: true, | |
configurable: true, | |
enumerable: false, | |
}); | |
} | |
getTempVariable(key: string) { | |
return this[key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TempVariableInserter classındaki methodlar bir classın içine JSON.stringify() methodu kullanıldığında JSON içinde bulunmayacak değişkenler eklenmesini sağlar.
DemoClass classında ise toJSON methodu classtaki gibi yazıldığında JSON.stringify() methoduyla JSON'a çevrildiğinde sadece foo ve bar değişkenleri JSON içinde bulunur. fooLabel ve barLabel değişkenleri JSON içerisinde yer almaz.