Advertisement
benshepherd

JS Class example

May 8th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //Create instance of box class
  3. var myBox = new Box(100,200);
  4.  
  5. console.log("Box width: " + myBox.Width);
  6. console.log("Box width: " + myBox.Height);
  7.  
  8. //Change box size with function
  9. myBox.changeSize(500,500);
  10.  
  11. //Change box size with variables
  12. myBox.Width = 500;
  13. myBox.Height = 500;
  14.  
  15.  
  16. //Box class
  17. function Box(width, height) {
  18.    
  19.     //Class variables
  20.     this.Width = width;
  21.     this.Height = height;
  22.    
  23.     //Class functions
  24.     this.SomeFunction = function() {
  25.    
  26.     }
  27.     this.changeSize = function(w,h) {
  28.         this.Width = w;
  29.         this.Height = h;
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement