Objects and Methods in Javascript

Using Codecademy, I have learned about Objects and Methods in Javascript. Here's an example of what I can do:

//Here is our rectangle with set length and width
var rectangle = new Object();
rectangle.length = 3;
rectangle.width = 4;

//To define a new length 
rectangle.setLength = function (newLength) {
  this.length = newLength;

//To define a new width 
rectangle.setWidth = function (newWidth) {
  this.width = newWidth;  

//Here we use the methods to change the values
This entry was posted in Computing and tagged , , , . Bookmark the permalink.

Leave a reply