Javascript 无法调用当前对象中的函数。为什么?

Javascript 无法调用当前对象中的函数。为什么?,javascript,jquery,Javascript,Jquery,我有一个名为Validation的函数,它包含三个函数。现在,当我想从Validation中的一个函数调用另一个函数时,即第13行。然后我得到了这个错误 Uncaught TypeError: Object [object Object] has no method 'validateAddress' 这是我的密码 var Validation = function () { var inputs, field, errors = [], self = this, emptyFieldsV

我有一个名为
Validation
的函数,它包含三个函数。现在,当我想从
Validation
中的一个函数调用另一个函数时,即第13行。然后我得到了这个错误

Uncaught TypeError: Object [object Object] has no method 'validateAddress' 
这是我的密码

var Validation = function () {
var inputs, field, errors = [], self = this,

emptyFieldsValidation = function () {
    $('#form input').each(function (i, el) {
        inputs = $(this);
        if ( inputs.val() == '' ) {
            inputs.css('border', '1px solid red');
            return errors.push('emptyFields');
        } else {
            inputs.css('border', '1px solid #ccc');
            if (inputs.hasClass('from')) {
                if (!self.validateAddress(inputs.val()))
                    errors.push('invalidFromAddress');
            }
            if (inputs.hasClass('to')) {
                if (!self.validateAddress(inputs.val()))
                    errors.push('invalidToAddress');
            }
            if (inputs.hasClass('time')) {
                if (!self.validateForNumber(inputs.val()))
                    errors.push('invalidTime');
            }
        }
    });
    return !!errors.length;
},

validateAddress = function (val) {
    var streetregex = /^[\w+\s]+\d+,\s*[\s\w]+$/;
    if (streetregex.test(val)) return true;
    else return false;
},

validateForNumber = function (val) {
    if (!isNaN(val)) return true;
    else return false;
};

return {
    emptyFieldsValidation: emptyFieldsValidation
};
}

emptyFieldsValidation
中的
self.validateAddress
替换为
validateAddress


您可以阅读有关嵌套函数和闭包的更多信息。

emptyFieldsValidation
中将
self.validateAddress
替换为
validateAddress


您可以阅读有关嵌套函数和闭包的更多信息。

验证不应该是
对象而不是
函数
?验证不应该是
对象而不是
函数