Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

javascript - 三元操作员确定对象值(Terniary operator to determine object value)

I have the following terniary operator :(我有以下三级运算符:)

[',' , '|' , ';' , 'TAB'].forEach(separator => separatorSelect.append($('<option>', separator === 'TAB' ? {value: '', text: separator} : {value: separator, text: separator}))); if separator === tab then the value in the object should be '\t'.(如果分隔符===制表符,则对象中的值应为'\ t'。) It works.(有用。) But I'm wondering if there's aa way to do the terniary inside the object itself so i wont have to copy the whole object twice.(但是我想知道是否有一种方法可以在对象本身内部进行三级处理,这样我就不必复制整个对象两次。) {value: 'terniary here?', text: separator} Is that possible or is my way the only way it can be done?(这是可能的还是我唯一的方法?)   ask by Kevin.a translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, it is:(是的:)

{ value: (separator === 'TAB' ? '' : separator), text: separator }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...