benshepherd icon

JS Class example

benshepherd | PRO | 05/08/13 06:56:51 PM UTC | 0 ⭐ | 296 👁️ | Never ⏰ | []
JavaScript |

550 B

|

None

|

0 👍

/

0 👎

 
//Create instance of box class
var myBox = new Box(100,200);
 
console.log("Box width: " + myBox.Width);
console.log("Box width: " + myBox.Height);
 
//Change box size with function
myBox.changeSize(500,500);
 
//Change box size with variables
myBox.Width = 500;
myBox.Height = 500;
 
 
//Box class
function Box(width, height) {
    
    //Class variables
    this.Width = width;
    this.Height = height;
    
    //Class functions
    this.SomeFunction = function() {
    
    }
    this.changeSize = function(w,h) {
        this.Width = w;
        this.Height = h;
    }
    
}

Comments