Last active
February 2, 2019 23:59
-
-
Save MateusAndrade/bf904e6cc2cfa78f7d1f114a4546e426 to your computer and use it in GitHub Desktop.
Returns all object propertys using this scope in a ES6 class parsed to a JSON
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
toJson(){ | |
let _obj: any = {}; | |
let _str:string = ""; | |
for (const key in this) { | |
if (this.hasOwnProperty(key)) { | |
_str = key; | |
_str = _str.replace(_str.charAt(0),""); | |
_obj[_str] = this["_"+_str]; | |
} | |
} | |
return JSON.stringify(_obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment