How to map JSON data to a class
问题 I created a ES6 class by Babel and I want to map JSON data which is gotten from a server to the ES6 class. Is there anything common way to do that? User.js export default class User { constructor() { this.firstName; this.lastName; this.sex; } } app.js import User from "./classes/User"; var data = JSON.parse(req.responseText); console.log(data.firstname); //Bob //now...just set data one by one? 回答1: I would merge the JSON object into this using Object.assign , as follows: class User {