Created
December 2, 2015 11:10
-
-
Save mitsuru793/2ed5dee301ce56c5c51d to your computer and use it in GitHub Desktop.
JavaScriptのクラスとインスタンスのprototypeは同じなのか?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.logのエイリアス | |
var l = function(x) { console.log(x); }; | |
prototypeOfConstructor = null | |
function People(name) { | |
this.name = name; | |
prototypeOfConstructor = this.prototype; | |
} | |
// Peopleを定義しただけで、中身が実行されていないことを確認 | |
l(prototypeOfConstructor); // null | |
suzuki = new People("suzuki"); | |
l(prototypeOfConstructor === People.prototype); // false | |
l(prototypeOfConstructor === suzuki.prototype); // true | |
l(People.prototype === suzuki.prototype); // false | |
// 上記から下記のことが分かりました。 | |
// * prototypeOfConstructorは、インスタンス変数のprototypeである。 | |
// * クラスとインスタンスのprototypeは別物 | |
// このクラスとはfuncitonオブジェクトのことを指しています。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment