Created
July 23, 2017 12:45
-
-
Save jacobandresen/1fb6f9664e2b732347590873b8584f02 to your computer and use it in GitHub Desktop.
module 3 - lesson 1 - homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment