I was stuck by an example in the conversion method of javascript Red Book 5.2.2.

Red Treasure Book, 5.2.2 conversion method

toLocaleString () methods often return the same values as toString () and valueOf () methods, but not always. When the toLocaleString () method of an array is called, it also creates a comma-separated string of array values. The only difference from the first two methods is that this time, in order to get the value of each item, the toLocaleString () method of each item is called instead of the toString () method. Take a look at the following example:

Gods, I"ll just go to the code:

alert(people.toString());             //Nicholas,Greg
alert(people.toLocaleString());       //Nikolaos,Grigorios

3. Is the above result obtained because of the two custom methods of the object, or directly through the call? Can you simply tell me what the process is like?

Mar.06,2021

alert (people) = alert (the parameter in people.toString ())
alert expects a string, so the toString method
is called automatically. The difference between toString and toLocalString is like the difference between two functions. There is no connection between
about why the array's toString and toLocalString are different from ordinary objects. The main reason is that the array overrides these two methods


.

Let's discuss the third question:
Let's take a look at your quotation about the contents of the Red Treasure Book at the beginning of the question:

. The only difference from the first two methods is that in order to get the value of each item this time, the toLocaleString () method of each item is called.

that is to say

  

to be honest, I don't understand this example. I think the answer upstairs is still far-fetched. Is there any

that can be explained in detail?
Menu