Thursday, 1 June 2017

How to access variable into function which is declared in outside of function

restData = currentNode.Restdata;
chain = {
    name: currentNode.name,
    body: function (job, cb) {

        var client = restify.createClient({
            url : restData.URL
        });

        switch (restData.Type) {
            case 'GET': 
                return client.get('/​​​', function (err, req, res, obj) {
                    if (err) {
                        return cb(err.name + ': ' + err.body.message);
                    } else {
                        return cb(null, 'Data found');
                    }
                });
                break;

            default:
                break;
        }                    
    }
};

In Above case, I can't access the restData variable into body: function () {}. Anyone can help me to solve this problem and i can access the restData into body function.



via Sudhir Vadodariya

No comments:

Post a Comment