Elegant ways to return multiple values from a function

后端 未结 14 865
梦谈多话
梦谈多话 2020-12-15 03:49

It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing.

The typical soluti

14条回答
  •  天涯浪人
    2020-12-15 04:46

    Even if you ignore the wonderful newer destructuring assignment Moss Collum mentioned, JavaScript is pretty nice on returning multiple results.

    function give7and5() {
      return {x:7,y:5};
    }
    
    a=give7and5();
    console.log(a.x,a.y);
    
    7  5
    

提交回复
热议问题