The application of arguments in JS

Source: Internet
Author: User

In JS, each function class has a arguments object instance arguments. First of all, he is not an array, it can be said to be a pseudo-array, but the index of the array can also get his value, such as

Let len = Arguments.length; Indicates the number of function arguments

Arguments[0] represents the first parameter

The advantage of using it in a function is that the function is called in multiple places and the parameters do not have to be passed, so it can be handled by using arguments, which solves the problem of unnecessary parameters being passed.

In the actual application of the function of the use of a bit, there is not the right and need to improve the place, but also please give us a lot of advice, study together

Export function Axiospost () {
Let len = arguments.length;
if (Len < 4) {
Alert (' Please check ' for incorrect parameters);
Return
}
Let that = arguments[0];
Let URL = arguments[1];
Let params = arguments[2];
Let callback = Arguments[3];
Let message;
let config;
if (len = = = 4) {
message = ";
config = {};
}
else if (len = = 5) {
config = arguments[4];
message = ";
}
else {
config = arguments[4];
message = Arguments[5];
}
Axios.post (URL, params, config)
. then (function (respons) {
Processresponsedata (That,respons,message,callback);
})
. catch (function (error) {
That. $message ({
Message: ' There is a problem with the data response ',
Type: ' ERROR '
});
});
}

This is a POST request encapsulation, is used in the Vue project, using Axios instead of Ajax to do the interaction, because the first four parameters must be passed, and then two parameters are not necessary is to do the expansion of use

The application of arguments in JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.