Skip to content

Instantly share code, notes, and snippets.

@olivier-spinelli
Created November 4, 2016 10:55
Show Gist options
  • Save olivier-spinelli/e6a1c54b361f41ccc6f1d933f75cf741 to your computer and use it in GitHub Desktop.
Save olivier-spinelli/e6a1c54b361f41ccc6f1d933f75cf741 to your computer and use it in GitHub Desktop.
function Animal( objectName ) {
this._name = objectName;
}
Animal.prototype._name = "Animal’s prototype.";
Animal.prototype.makeNoise = function () { console.log( this._name + ' is silent.' ); };
Animal.prototype.run = function () { console.log( this._name + ' runs.' ); };
var a = new Animal( "Basic Animal." );
a.makeNoise();
function Dog( objectName ) {
this._name = objectName;
}
Dog.prototype = new Animal( "Dog’s prototype." );
Dog.prototype.makeNoise = function () { console.log( this._name + ' is barking.' ); };
//var pAnimal = Animal.prototype;
//delete pAnimal.run;
delete Animal.prototype.run;
//Animal.prototype = Dog.prototype;
var m = new Dog( "Médor" );
m.makeNoise();
m.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment