开发者

Create a function and assign its return to a variable

Is there a one line way of doing this? Eg:

var myVare = function(params){
   if(param.condition){
  开发者_JAVA百科     return 'a';
   }else{ 
       return 'b'; 
   }
}(param:{condition:'abc'}); 

console.log(myVare);//I would like it to be == to 'a'


You're working too hard.

var myVare = {condition: 'abc'}.condition ? 'a' : 'b';

console.log(myVare); // 'a'


var myVare = function(param){return param.condition ? 'a' : 'b';}({condition:'abc'});

That's one line. I'm not sure what you are trying to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜