如果||,我应该如何格式化当前的电流(或)陈述?

时间:2015-01-30 09:46:06

标签: javascript

这就是我现在所拥有的:

  if (user.userId && _.include(Session.get('onlineEditors'), user.userId)) {
    return Meteor.users.findOne({_id: user.userId})
  }

现在我想添加一个|| (或)if语句开头的替代方案。比方说,变量currentUserId

所以代码会说:如果currentUserId为真或user.userId && _.include(Session.get('onlineEditors'), user.userId)为真

如何正确格式化?

2 个答案:

答案 0 :(得分:3)

if (currentUserId || (user.userId && _.include(Session.get('onlineEditors'), user.userId)))

答案 1 :(得分:0)

if (currentUserId != null || (user.userId != null &&
_.include(Session.get('onlineEditors'), user.userId)))

这是你的意思吗?