Intro to objects: make your own method


var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height
rectangle.setHeight = function (newHeight) {
this.height = newHeight;

rectangle.setWidth = function (newWidth) {
this.width = newWidth;

rectangle.setWidth = setWidth;
rectangle.setHeight = setHeight;


For some reason the setWidth is not being defined.. I don't know what I did wrong


The above lines are an attempt to assign an undefined object to an already defined variable. Both lines may be removed.

Again, these lines refer to undefined objects. Should be,