所以我正在做一个粗俗的项目。我一直在跟着,然后我必须将一个对象返回到控制台以测试某些东西,唯一的问题是,它没有返回该对象,它只是返回了该对象所在的代码部分,包括诸如注释之类的东西。这是代码:
var UIController = (function() {
var DOMstrings = {
inputType: '.add__type',
inputDescription: '.add__description',
inputValue: '.add__value',
inputBtn: '.add__btn',
incomeContainer: '.income__list',
expensesContainer: '.expenses__list',
budgetLabel: '.budget__value',
incomeLabel: '.budget__income--value',
expensesLabel: '.budget__expenses--value',
percentageLabel: '.budget__expenses--percentage',
container: '.container',
expensesPercLabel: '.item__percentage',
dateLabel: '.budget__title--month'
};
return {
getinput: function() {
var items = {
type: document.querySelector(DOMstrings.inputType).nodeValue,
description: document.querySelector(DOMstrings.inputDescription).nodeValue,
value: document.querySelector(DOMstrings.inputValue).nodeValue
}
return items;
}
}
}
)();
// Global App Controller
var controller = (function(budgetCtrl, UICtrl) {
var ctrlAddItem = function() {
// 1. Get the filled input data
var input = UICtrl.getinput;
console.log(input);
// 2. Add the item to the budget controller
// 3. Add the new item to the user interface
// 4. Calculate the budget
// 5. Display the budget on the UI
}
document.querySelector('.add__btn').addEventListener('click', ctrlAddItem);
// Make the ENTER key do what the CLICK does
document.addEventListener('keypress', function(event) {
if (event.keyCode === 13 || event.which === 13) {
console.log('ENTER was pressed');
ctrlAddItem();
}
} );
})(budgetController, UIController);
这是输出:
ƒ () {
var items = {
type: document.querySelector(DOMstrings.inputType).nodeValue,
description: document.querySelector(DOMstrings.inputDescription).nodeV…
先谢谢您
答案 0 :(得分:1)
将var input = UICtrl.getinput;
更改为var input = UICtrl.getinput();