Skip to content

Instantly share code, notes, and snippets.

@lisaSwanson
Forked from stujo/constructor_with_prototype.js
Last active August 29, 2015 14:28
Show Gist options
  • Save lisaSwanson/ba467a1ebc0d57850fb3 to your computer and use it in GitHub Desktop.
Save lisaSwanson/ba467a1ebc0d57850fb3 to your computer and use it in GitHub Desktop.
Prototypical Dinosaurs
function Dinosaur(color){
this.id = Dinosaur.prototype.counter++;
this.dob = Date.now();
this.color = color;
};
Dinosaur.prototype.roar = function(){
console.log('RARWARARRR said the ' + this.color + ' Dinosaur!!!');
};
Dinosaur.prototype.counter = 1000;
var o = new Dinosaur('blue');
var reddy = new Dinosaur('red');
console.log(o);
console.log(reddy);
o.roar();
reddy.roar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment