An instance of implementing multiple return values of function return in JS

  • 2021-07-22 08:46:46
  • OfStack

Recently, I started the front-end work of web, mainly using JS, html5+css, and JS framework (jQuery, dojo, etc.). In the process of learning and writing code, I have some small experiences to communicate and learn with you.

Today, we mainly focus on the method of "JS implements multiple return values of function return".

1. The basic method of the function is as follows:


functionA(fp1 , fp2 , fp3){

.......

return {a1:a,b1:b,c1:c}; // The value that will be obtained a,b,c Encapsulated in 1 The fields are a1,b1,c1 In the object of 

}

2. Call the function:

Call functionA (fp1, fp2, fp3); The following fpp1, fpp2 and fpp3 are arguments (functions and object-oriented ideas will not be mentioned here, I believe they have learned C language and understood object-oriented ideas)

var obj=functionA (fpp1, fpp2, fpp3); //Call function functionA and pass parameters at the same time

var fun1=obj. a1; //Get the value of the object field a through the obj object

var fun2=obj. b1; //Get the value of b

var fun3=obj. c1; //Get the value of c


Related articles: