Ternary Operator in JavaScript With Multiple Expressions?

后端 未结 6 1998
再見小時候
再見小時候 2021-01-17 14:29
the_styles ? the_styles.appendTo(\'head\'); the_styles=null : the_styles = $(\'.stylesheet\').detach();

Obviously, this isn\'t valid. Notice the \"

6条回答
  •  无人及你
    2021-01-17 14:52

    the_styles ? (function() {the_styles.appendTo('head'); the_styles=null})() : 
    

    Just wrap the code block in (function() { and })().

    Now for the hard part: why would you want to do this? Perhaps there's a better solution!

提交回复
热议问题