“This is the third day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Function: family (country)

This: Language (Chinese)

Internal variables, Internal methods: a long history and cultural heritage

We can regard function as the development history of a country, this is the language used for communication in this country, and internal variables and methods can be regarded as the long historical and cultural heritage inherited from this country.

Our country has a long history, experienced the various dynasties and generations, experienced the smoke of war, our ancestors through the efforts of generation after generation, gave us a rich cultural heritage, we also through learning these cultural heritage, set up their own small family, more let the motherland this big family continues to grow.

Similarly, the same situation exists in the development of the great family of functions.

Function Pre(a, b) {this.a = a; // this. B = b; // this. C = 'c'; Function Pre1(a, b) {Pre1(a, b) {pre.call (this, a, b); A, b, c this.d = 'd1'; Function Pre2(a, b) {pre.apply (this, [a, b]); function Pre2(a, b) {pre.apply (this, [a, b]); A, b, c this.d = 'd2'; // Pre2 Through continuous efforts on the basis of their fathers, This. Count = 99} // Pre21 is the first child of Pre2. Function Pre21(a, b) { Pre2.bind(this); A, b, c, d, count this.countS = this.count * 2; // Pre21 inherits the count left by Pre2 and through its own efforts 💪, } // Other children of Pre and offspring of Pre1, Pre2, and Pre21 can also inherit assets left by their parents through call, apply, and bindCopy the code

The rise of the family of functions (with Pre as the initiator) is as simple as that. Each generation of functions inherits (call, apply, bind) assets from their parent generation (internal variables of Pre, internal methods…). “, and constantly strive to develop and acquire their own assets (other variables and methods in the lexical scope of call) and pass them on to future generations as capital for development.

Summary:

fn.call(this, a, b)

fn.apply(this, [a, b])

fn.bind(this, [, arg1[, arg2[, ...]]])

The first argument to call, apply, and bind is to bind this to the current scope

The second argument to call is the argument list

The second argument to apply is an array of parameters

The second argument to bind can be either a list of arguments or a currified argument

Note:

A function that bind returns

If the function returned by Bind is referred to as a constructor by new, this points to an instance of the current constructor, not this in the scope of bind's binding