Created
February 24, 2020 07:36
-
-
Save gpDA/bdb2e81daa10130ffe28343da28a5a49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Car(model, year, miles) { | |
| this.model = model; | |
| this.year = year; | |
| this.miles = miles; | |
| } | |
| // Note here that we are using Object.prototype.newmethod rather than | |
| // Object.prototype so as to avoid redefining the prototype object | |
| Car.prototype.toString = function () { | |
| return this.model + " has done " + this.miles + " miles"; | |
| } | |
| // Usage | |
| var civic = new Car("Honda Civic", 2009, 20000); | |
| var mondeo = new Car("Ford Mondeo", 2010, 5000); | |
| console.log(civic.toString()); // Honda Civic has done 20000 miles | |
| console.log(mondeo.toString()); // Ford Mondeo has done 5000 miles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment