Skip to content

Instantly share code, notes, and snippets.

@suguanYang
Last active May 25, 2019 03:21
Show Gist options
  • Save suguanYang/d2c011267588ba796010fab06f4740c1 to your computer and use it in GitHub Desktop.
Save suguanYang/d2c011267588ba796010fab06f4740c1 to your computer and use it in GitHub Desktop.
Javascript prototype

prototype

The prototype is a property of a functionconstructor function or classes6. It used for define class's members, like fields and methods, and it's instance(new) will inherit these members. When an instance calls the members it inherited from a class, it dosent look for it's prototype, beacuse an instance dosent has prototype property. What are the members come form? The __proto__ do this, so we talk about 'protorype chain' more likes __proto__.__proto__.__proto__ than protorype.protorype.protorype, the instance.__proto_ === class.prototype is true. we find members from it! So what the prototype is? from the above, we know when we create a instance, the __proto__ will refers to prototype object, we also can say it is used for create __proto__

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