Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //OOP in javascript
  2. function Car(speed){
  3. this.speed = speed;
  4. this.getSpeed = function() {
  5. return "Speed of the Car: " + this.speed
  6. }
  7. }
  8.  
  9. //Instanzierung
  10. var car1 = new Car(10);
  11. console.log(car1);
  12. console.log(car1.speed);
  13. console.log(car1.getSpeed());
  14.  
  15. //Adding Properties and Methods to an Object
  16. var car2 = new Car(20);
  17. car2.color = "red";
  18. car2.getColor = function(){
  19. return "Color of the Car: " + this.color
  20. }
  21.  
  22. console.log(car1);
  23. console.log(car1.color);
  24. console.log(car1.getColor);
  25.  
  26. console.log(car2);
  27. console.log(car2.color);
  28. console.log(car2.getColor());
  29.  
  30. //Adding Properties and Methods to a Prototyp
  31. Car.prototype.weight = "100";
  32. var car3 = new Car(30);
  33. console.log(car3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement