Skip to content

Instantly share code, notes, and snippets.

@shigeki
Created October 15, 2012 04:13
Show Gist options
  • Save shigeki/3890790 to your computer and use it in GitHub Desktop.
Save shigeki/3890790 to your computer and use it in GitHub Desktop.
prototype.__proto__ と util.inherits() の違い
function Animal() {}
function Ferret() {}
Ferret.prototype.eat = true;
Ferret.prototype.__proto__ = Animal.prototype;
Ferret.prototype.bark = false;
var ferret = new Ferret();
console.log(ferret.eat, ferret.bark);
function Animal() {}
function Ferret() {}
Ferret.prototype.eat = true;
require('util').inherits(Ferret, Animal);
Ferret.prototype.bark = false;
var ferret = new Ferret();
console.log(ferret.eat, ferret.bark);
@shigeki
Copy link
Author

shigeki commented Oct 15, 2012

結果:

> node ./test1.js
true false
> node ./test2.js
undefined false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment