JavaScript 不会返回对象,它只返回代码部分

标签 javascript object

所以我正在做一个项目,它是 udemy 类(class)的一部分。我一直在跟踪,然后我必须将一个对象返回到控制台来测试某些内容,唯一的问题是,它不返回该对象,它只返回该对象所在的代码部分,包括注释之类的内容。这是代码:

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…

提前谢谢您。

最佳答案

var input = UICtrl.getinput; 更改为 var input = UICtrl.getinput();

关于JavaScript 不会返回对象,它只返回代码部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074288/

相关文章:

java - 无法更新静态变量(容易修复吗?)(Java)

java - 在Java中通过txt文件创建对象到数组中

javascript - 为尚未单击的元素添加阴影

javascript - 多个文件上的相同函数闭包

javascript - 最佳实践 - 在显示 :none, 的文档中预写 HTML 或使用 JS 创建?

javascript - 我的 DIY trim 函数无法返回正确答案,它返回未定义

javascript - 在提交之前操纵表单值而不向用户显示?

javascript - 如何迭代数组中的值以匹配对象中的值并返回相应的对象?

javascript - 如何访问在 IF/ELSE 范围之外创建的变量、在 IF 语句中更新它以及在 ELSE 语句中访问该更新?

Java:无法在比较器中将对象转换为日期