Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Recipe {
- name: string;
- author: User;
- // class properties instantiated from contructor parameters
- constructor(name: string, author: User) {
- this.name = name;
- this.author = User;
- }
- }
- class User {
- name: string;
- constructor(name: string) {
- this.name = name;
- }
- }
- var json = {
- name: 'Pizza Italia'
- author: {
- name: 'John Doe'
- }
- };
- var serializedJson = JSON.parse(json);
- // this can get ugly very quickly...
- var user = new User(serializedJson.name);
- var recipe = new Recipe(serializedJson.name, user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement