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.
精彩评论