user defined function with callback in nodejs

前端 未结 2 1483
抹茶落季
抹茶落季 2021-02-14 03:13

can anyone give me an example in which we are creating a particular function, which is also having a callback function ?

function login(username, password, funct         


        
2条回答
  •  北海茫月
    2021-02-14 03:48

    Here's an example of the login function:

    function login(username, password, callback) {
        var info = {user: username, pwd: password};
        request.post({url: "https://www.adomain.com/login", formData: info}, function(err, response) {
            callback(err, response);
        });
    }
    

    And calling the login function

    login("bob", "wonderland", function(err, result)  {
        if (err) {
            // login did not succeed
        } else {
            // login successful
        }
    });
    

提交回复
热议问题