Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OOP in javascript
- function Car(speed){
- this.speed = speed;
- this.getSpeed = function() {
- return "Speed of the Car: " + this.speed
- }
- }
- //Instanzierung
- var car1 = new Car(10);
- console.log(car1);
- console.log(car1.speed);
- console.log(car1.getSpeed());
- //Adding Properties and Methods to an Object
- var car2 = new Car(20);
- car2.color = "red";
- car2.getColor = function(){
- return "Color of the Car: " + this.color
- }
- console.log(car1);
- console.log(car1.color);
- console.log(car1.getColor);
- console.log(car2);
- console.log(car2.color);
- console.log(car2.getColor());
- //Adding Properties and Methods to a Prototyp
- Car.prototype.weight = "100";
- var car3 = new Car(30);
- console.log(car3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement