简体   繁体   中英

JavaScript won't return object, it just returns the section of code

so im doing a project thats apart of an a udemy course. I was following along and then i have to return an object to the console to test something, only problem is, it doesnt return the object, it just returns the section of code the object is in, including things like comments. here's the code:

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);

and here is the output:

ƒ () { 
       var items = {
            type: document.querySelector(DOMstrings.inputType).nodeValue, 
            description: document.querySelector(DOMstrings.inputDescription).nodeV…

thank you in advance.

Change var input = UICtrl.getinput; into var input = UICtrl.getinput();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM