Javascript 未捕获类型错误:UICtrl.getDOMstrings不是函数
我在控制台中遇到的确切错误是:Javascript 未捕获类型错误:UICtrl.getDOMstrings不是函数,javascript,dom,closures,Javascript,Dom,Closures,我在控制台中遇到的确切错误是: var budgetController = (function() { })(); //UI CONTROLLER var UIController = (function () { var DOMstrings = { //so i won't have to change '.add__type' for example everywhere in the code if i decide to modify my html
var budgetController = (function() {
})();
//UI CONTROLLER
var UIController = (function () {
var DOMstrings = {
//so i won't have to change '.add__type' for example everywhere in the code if i decide to modify my html
inputType: '.add__type',
inputDescription: '.add__description',
inputValue: '.add__value',
inputBtn: '.add__btn'
};
return {
getInput: function(){
return {
type: document.querySelector(DOMstrings.inputType).value,//will be wither inc or exp
description: document.querySelector(DOMstrings.inputDescription).value,
value: document.querySelector(DOMstrings.inputValue).value
};
},
getDomstrings: function() {
//exposing the domstring object to the public
return DOMstrings;
}
};
})();
//GLOBAL APP CONTROLLER
var controller = (function(budgetCtrl,UICtrl) {
var DOM = UICtrl.getDOMstrings();
var ctrlAddItem = function () {
//1. get the field input data
var input = UICtrl.getInput();
console.log(input);
//2.Add the item to the budget controller
//3.Add the item to the UI
//4. Calculate the budget
//5. Display the budget on the UI
}
document.querySelector(DOM.inputBtn).addEventListener('click',ctrlAddItem);
document.addEventListener('keypress', function(event) {
// enter has that key code(13)
if (event.keyCode === 13 || event.which === 13) {
ctrlAddItem();
}
});
})(budgetController,UIController);
正在积极学习javascript,并在错误上陷入困境,因为
。getDomstrings()
是上面定义的函数,是公共函数,因此应该可以访问它。可能不需要添加html,但如果评论中有,请告诉我。Javascript是区分大小写的语言,使用时必须使用与语言关键字、函数、变量等完全相同的名称
因此,函数getDomstrings
在被称为getDomstrings
时无效
必须以getDomstrings
的形式调用函数,或者将函数名更改为getDomstrings
,然后才能以getDomstrings
的形式调用函数
因此,请输入以下代码:
var-DOM=UICtrl.getDOMstrings()代码>
应该是:
var-DOM=UICtrl.getDomstrings()代码>
app.js:39 Uncaught TypeError: UICtrl.getDOMstrings is not a function
at app.js:39
at app.js:68
(anonymous) @ app.js:39
(anonymous) @ app.js:68