Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Homework:
- ---------
- In classs you learned about IIFE's, encapsulation and object oriented programming.
- You also worked on a example calling library_a.render() and library_b.render().
- IIFE's are good for grouping related code in a namespace. Let's say that you have some math related functions . Then
- you could do:
- var Math = (function () {
- return {
- Rectangle: function (height, width) {
- return {
- calcArea: function () {
- return height*width;
- }
- };
- },
- Triangle: function (A, B, C) {
- // .. insert code here ...
- }
- };
- })();
- var rectangle = new Math.Rectangle(10,10);
- console.log(rectangle.calcArea());
- var triangle = new Math.Triangle(6,8,10);
- //console.log(triangle.calcArea());
- Your task: insert code into the Math.Triangle class that
- will make console.log(triangle.calcArea()) print out the area of a triangle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement