Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Homework:
  2. ---------
  3. In classs you learned about IIFE's, encapsulation and object oriented programming.
  4. You also worked on a example calling library_a.render() and library_b.render().
  5.  
  6. IIFE's are good for grouping related code in a namespace. Let's say that you have some math related functions . Then
  7. you could do:
  8.  
  9. var Math = (function () {
  10. return {
  11. Rectangle: function (height, width) {
  12. return {
  13. calcArea: function () {
  14. return height*width;
  15. }
  16. };
  17. },
  18. Triangle: function (A, B, C) {
  19. // .. insert code here ...
  20. }
  21. };
  22. })();
  23.  
  24. var rectangle = new Math.Rectangle(10,10);
  25. console.log(rectangle.calcArea());
  26. var triangle = new Math.Triangle(6,8,10);
  27. //console.log(triangle.calcArea());
  28.  
  29. Your task: insert code into the Math.Triangle class that
  30. will make console.log(triangle.calcArea()) print out the area of a triangle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement