This file contains 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
Rectangle = function(w,h) { | |
return { | |
width: w, | |
height: h, | |
area: function() { return w * h }, | |
}; | |
}; |
This file contains 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
var rect = new Rectangle(2,3); | |
document.write('area: ' + rect.area() + '<br/>'); |
This file contains 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
var rect = new Rectangle(2,3); | |
document.write('area : ' + rect.area() + '<br/>'); | |
rect.width = 5; | |
document.write('area : ' + rect.area() + '<br/>'); |
This file contains 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
area: function() { return w * h } |
This file contains 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
area: function() { return this.width * this.height } |
This file contains 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
Rectangle = function(w,h) { | |
return { | |
width: w, | |
height: h, | |
area: function() { return this.width * this.height }, | |
toString: function() { return '(' + this.width + 'X' + this.height + ')' } | |
}; | |
}; |
This file contains 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
var rect = new Rectangle(2,3); | |
document.write('area of ' + rect + ': ' + rect.area() + '<br/>'); | |
rect.width = 5; | |
document.write('area of ' + rect + ': ' + rect.area() + '<br/>'); |
This file contains 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
Rectangle = function(w,h) { | |
var width = w, height = h; | |
return { | |
getWidth: function() { return width; }, | |
getHeight: function() { return height; }, | |
setWidth: function(w) { width = w; }, | |
setHeight: function(h) { height = h; }, | |
area: function() { return width * height }, | |
toString: function() { return '(' + width + 'X' + height + ')' } | |
}; |
This file contains 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
var rect = new Rectangle(2,3); | |
document.write('area of ' + rect + ': ' + rect.area() + '<br/>'); | |
rect.setWidth(5); | |
document.write('area of ' + rect + ': ' + rect.area() + '<br/>'); |
This file contains 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
Rectangle.prototype.perimeter = function() { | |
return 2 * this.getWidth() + 2 * this.getHeight(); | |
}; |