using multiple return statements in JavaScript

前端 未结 4 1728
忘掉有多难
忘掉有多难 2021-01-16 12:26

I am trying to use multiple returns but just keep breaking the code. I have tried a few examples, but cant find the right combination.

How can I combine these two r

4条回答
  •  野的像风
    2021-01-16 12:50

    Putting aside this specific case, where the plugin demands a certain type of return value (apparently a string in this case), you can't really... A return statement terminates the function. What you'll have to do is return an object (or an array) containing those two values -

    var status = $(this).data('dataObj').status;
    var timeline = $(this).data('dataObj').timeline;
    return [status,timeline];
    

    Or

    var status = $(this).data('dataObj').status;
    var timeline = $(this).data('dataObj').timeline;
    var returnObj = {'status':status, 'timeline':timeline};
    return returnObj;
    

提交回复
热议问题