-
-
Save Bijesse/9dac0b8f4aa45f8711baf8f0fb1f6c81 to your computer and use it in GitHub Desktop.
Constructor code along.. geometry ex // source http://jsbin.com/leketu
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Constructor code along.. geometry ex</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// 1) Create a Rectangle constructor that has "length" and "width" instance properties | |
// 2) Assign Rectangle.prototype a function, getArea, that returns the rectangle's area | |
// 3) Create a Square constructor that has a "size" instance property | |
// 4) Square should inherit from the Rectangle constructor | |
// Bonus: Use Rectangle's constructor inside of Square | |
function Rectangle(length, width){ | |
this.width = width; | |
this.length = length; | |
} | |
Rectangle.prototype.getArea = function(){ | |
console.log( this.length * this.width); | |
} | |
//Square inherits from Rectangle | |
function Square (size){ | |
this.length = size; | |
this.width = size; | |
} | |
Square.prototype = new Rectangle(); | |
var rect = new Rectangle(4,10); | |
var square = new Square(5); | |
square.getArea(); | |
rect.getArea(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// 1) Create a Rectangle constructor that has "length" and "width" instance properties | |
// 2) Assign Rectangle.prototype a function, getArea, that returns the rectangle's area | |
// 3) Create a Square constructor that has a "size" instance property | |
// 4) Square should inherit from the Rectangle constructor | |
// Bonus: Use Rectangle's constructor inside of Square | |
function Rectangle(length, width){ | |
this.width = width; | |
this.length = length; | |
} | |
Rectangle.prototype.getArea = function(){ | |
console.log( this.length * this.width); | |
} | |
//Square inherits from Rectangle | |
function Square (size){ | |
this.length = size; | |
this.width = size; | |
} | |
Square.prototype = new Rectangle(); | |
var rect = new Rectangle(4,10); | |
var square = new Square(5); | |
square.getArea(); | |
rect.getArea();</script></body> | |
</html> |
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
// 1) Create a Rectangle constructor that has "length" and "width" instance properties | |
// 2) Assign Rectangle.prototype a function, getArea, that returns the rectangle's area | |
// 3) Create a Square constructor that has a "size" instance property | |
// 4) Square should inherit from the Rectangle constructor | |
// Bonus: Use Rectangle's constructor inside of Square | |
function Rectangle(length, width){ | |
this.width = width; | |
this.length = length; | |
} | |
Rectangle.prototype.getArea = function(){ | |
console.log( this.length * this.width); | |
} | |
//Square inherits from Rectangle | |
function Square (size){ | |
this.length = size; | |
this.width = size; | |
} | |
Square.prototype = new Rectangle(); | |
var rect = new Rectangle(4,10); | |
var square = new Square(5); | |
square.getArea(); | |
rect.getArea(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment