using multiple return statements in JavaScript

前端 未结 4 1775
忘掉有多难
忘掉有多难 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:46

    Use

    function (){
        return $(this).data('dataObj');
    }
    

    OR

    function (){
        // return an array
        return [ $(this).data('dataObj').status, $(this).data('dataObj').timeline ]
    }
    

    OR

    function (){
        // return a associative array
        return { "status": $(this).data('dataObj').status, "timeline": $(this).data('dataObj').timeline }
    }
    

    And process the components in the caller.

    Update

    The content parameter for popover needs a string as argument, you can do this:

    function (){
        return $(this).data('dataObj').status + " " + $(this).data('dataObj').timeline;
    }
    

提交回复
热议问题