流星 - 返回虚假

时间:2016-02-27 00:12:46

标签: javascript meteor

在此代码中,最后return false;做了什么?

Template.register.events({
  'submit #register-form': function(event, template) {
    event.preventDefault();
    // Get input values
    var email = template.find('#account-email').value,
      password = template.find('#account-password').value;

    // Trim and validate Email
    var trimInput = function(val) {
      return val.replace(/^\s*|\s*$/g, "");
    }
    var email = trimInput(email);

    // Validate Password
    var isValidPassword = function(value) {
      if (value.length >= 6) {
        return true;
      } else {
        sAlert.error('Your password must be at least 6 characters long');
        return false;
      }
    }

    // If Password ok -> Register user
    if (isValidPassword(password)) {
      Accounts.createUser({
        email: email,
        password: password
      }, function(error) {
        if (error) {
          // Inform the user that account creation failed
          sAlert.error('Account creation failed for unknown reasons');
        } else {
          // Success. Account has been created and the user
          // has logged in successfully.
          sAlert.success('Account created successfully');
        }
      });
    }
    return false;
  }
});

2 个答案:

答案 0 :(得分:1)

从它的外观来看,如果代码一直到底,它看起来似乎是提供false响应。

答案 1 :(得分:0)

isValidPassword()是一个返回布尔值(true或false)的函数。此脚本允许用户在返回true时继续创建帐户