Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. class Recipe {
  2. name: string;
  3. author: User;
  4.  
  5. // class properties instantiated from contructor parameters
  6. constructor(name: string, author: User) {
  7. this.name = name;
  8. this.author = User;
  9. }
  10. }
  11.  
  12. class User {
  13. name: string;
  14.  
  15. constructor(name: string) {
  16. this.name = name;
  17. }
  18. }
  19.  
  20. var json = {
  21. name: 'Pizza Italia'
  22. author: {
  23. name: 'John Doe'
  24. }
  25. };
  26.  
  27. var serializedJson = JSON.parse(json);
  28. // this can get ugly very quickly...
  29. var user = new User(serializedJson.name);
  30. var recipe = new Recipe(serializedJson.name, user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement