Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // Bad
  2. function foo (obj) {
  3.  
  4. let result;
  5.  
  6. if (typeof obj === 'object' && obj.hasOwnProperty('value')) {
  7.  
  8. let data = getData(obj.value);
  9.  
  10. if (data.foo) {
  11. result = convert(data.foo);
  12. } else {
  13. result = null;
  14. }
  15.  
  16. }
  17.  
  18. return result;
  19. }
  20.  
  21. // Good
  22. function foo (obj) {
  23.  
  24. if (typeof obj !== 'object' || !obj.hasOwnProperty('value')) {
  25. return null;
  26. }
  27.  
  28. let data = getData(obj.value);
  29.  
  30. if (!data.foo) {
  31. return null;
  32. }
  33.  
  34. return convert(data.foo);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement