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);
我在控制台中得到的确切错误是:
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
积极学习javascript并停留在该错误上,因为
.getDomstrings()
是上面定义的函数,并且是公共函数,因此应该可以访问它。并且可能不需要添加html,但是如果有的话请在注释中告诉我。 最佳答案
Javascript是区分大小写的语言,使用它们时,必须使用与语言关键字,函数,变量等完全相同的名称。
因此您的函数getDomstrings
在称为getDOMstrings
时无效。
您必须以getDomstrings
调用函数或将函数名称更改为getDOMstrings
,然后才能以getDOMstrings
调用。
所以你下面的代码:var DOM = UICtrl.getDOMstrings();
应该:var DOM = UICtrl.getDomstrings();
关于javascript - 未捕获的TypeError:UICtrl.getDOMstrings不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51011618/