Advertisement
sami-jnih

{nodeJS} Héritage JavaScript

Mar 4th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ( typeof Object.create !== "function" ) {
  2.     Object.create = function (o) {
  3.         var F = function () {};
  4.         F.prototype = o;
  5.         return new F();
  6.     };
  7. }
  8.  
  9. var Engin = function (carbu) {
  10.     this.carbu = typeof carbu !== "string" ? "diesel" : carbu;
  11. };
  12. Engin.prototype = {
  13.     roule: function () {
  14.         return this.carbu + ' vroum engin! ;3';
  15.     }
  16. };
  17.  
  18. var Voiture = function (carbu) {
  19.     this.carbu = typeof carbu !== "string" ? "sans plomb" : carbu;
  20. };
  21. Voiture.prototype = Object.create(Engin.prototype);
  22. Voiture.prototype = {
  23.     roule: function () {
  24.         return this.carbu + ' vroum voiture :3';
  25.     }
  26. };
  27.  
  28. var Tracteur = function (carbu) {
  29.     this.carbu = typeof carbu !== "string" ? "trac" : carbu;
  30. };
  31. Tracteur.prototype = Object.create(Engin.prototype);
  32. Tracteur.prototype = {
  33.     roule: function () {
  34.         return this.carbu + ' vroum tracteur :3';
  35.     }
  36. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement