3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでのプロトタイプ継承

Last updated at Posted at 2015-04-22

JavaScriptでのプロトタイプ継承

function MyClass(x, y){
  this.x = x
  this.y = y
}

MyClass.prototype
// MyClass {}
// 全ての関数はprotytypeという名前のプロパティをもつ

//プロトタイプ継承
MyClass.prototype.info = function() {
  print(this.x, this.y)
}

var obj = new MyClass(5, 4);
obj.info(); //結果: 5 4

obj.__proto__
// MyClass {info: function}
// 全てのオブジェクトはコンストラクタのprototypeオブジェクトに__proto__プロパティで参照できる
  • 全ての関数はprototypeという名前のプロパティをもつ
  • 全てのオブジェクトはコンストラクタのprototypeオブジェクトに__proto__プロパティで参照できる
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?