Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constructor Pattern
- // -------------------
- // Basic Constructor
- function Car(make, model, year) {
- this.make = make;
- this.model = model;
- this.year = year;
- callIt = function() {
- return "demo:";
- }
- this.callItAll = function() {
- return callIt()+this.make+this.model+this.year;
- }
- }
- var audi = new Car(' Audi ',' A7 ',2007);
- var tesla = new Car(' Tesla ',' Model S ',2017);
- console.log(audi);
- console.log(audi.callItAll());
- console.log(tesla);
- console.log(tesla.callItAll());
- //console.log(audi.callIt());
- // With prototypes
- function Bike(make, model, year) {
- this.make = make;
- this.model = model;
- this.year = year;
- callIt = function() {
- return "demo:";
- }
- }
- Bike.prototype.callItAll = function() {
- return callIt()+this.make+this.model+this.year;
- }
- var harley = new Bike(' Harley ',' Iron ',2007);
- var ducati = new Bike(' Ducati ',' Diavel ',2017);
- console.log(harley);
- console.log(harley.callItAll());
- console.log(ducati);
- console.log(ducati.callItAll());
Add Comment
Please, Sign In to add comment