8
8

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.

プロトタイプチェーンの理解

Last updated at Posted at 2015-04-29

普段rubyを書いていて、メタプログラミングrubyとか読んで勉強しているのだけど、javascriptもやらなきゃなと思っていろいろ勉強を始めている。

いまいちプロトタイプベースというのが理解できなくて、うじゃうじゃnodeのコンソールでいじっていたのだけど、だんだんわかってきたので図に書いてみた。

写真 (1).JPG

・すべてはオブジェクトである
・ただ、クラスみたいな概念は存在する。

クラスみたいな概念といっているのは、rubyでいうオブジェクトのメソッド探索はオブジェクト自身→そのクラスのメソッド→その親クラスのメソッド(厳密には違いますが、そこはメタプログラミングrubyを参考)のように探索していくのだけど、javascriptの場合はプロトタイプチェーンという方式で、__proto__をさかのぼって探索がされていくというところ。かなと。
だから、クラスっぽく見えるのだけど、すべてはオブジェクトです。

8
8
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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?