Advertisement
tourniquet

JavaScript prototype with local variable

Mar 4th, 2015
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Dog(breed, weight, height, age) {
  2.     this.breed = breed;
  3.     this.weight = weight;
  4.     this.height = height;
  5.     this.age = age;
  6.     // local variable 'food'
  7.     var food = 'Chappie';
  8. };
  9.  
  10. var myDog = new Dog('Husky', '21kg', '53cm', 2);
  11. // myDog.breed -> Husky
  12. // myDog.height -> 53cm
  13. // myDog.food -> undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement