JSON to Javascript Class
问题 I have a http request that gets this Json object from a nosql database: let jsonBody = { birthday : 1997, firstname: 'foo', lastname:'bar' } Then I want to load this information into the Student model: class Student{ constructor(){ } getFullname(){ return this.lastname+' '+this.firstname } getApproxAge(){ return 2018- this.birthday } } Normally, I would add this method to this class: fromJson(json){ this.studentId = json.studentId; this.birthday = json.birthday; this.firstname = json