Scope/Scope Chain vs. Prototype/Prototype Chain

1. Scope

The scope is the execution environment of the code, the global execution environment is the global scope, and the execution environment of the function is the private scope, all of which are stack memory.

2. Scope chain

When code is executed in an execution environment, a scope chain (chain of scopes) of variable objects is created

3. Prototype

Whenever a data type is defined, it will be born with a prototype attribute, which points to the prototype object of the function, and this attribute is a value of the object data type.

4. Prototype chain

In JavaScript, the prototype object points to the parent class object until it points to the Object object, thus forming a prototype-pointed joint debugging, called the prototype chain. When accessing a property or method of an object, it will look for it in the object itself, if there is one, use it directly, if not, it will look it up in the prototype object, if it finds it, use it directly

Guess you like

Origin blog.csdn.net/weixin_54722719/article/details/123473266