Why is the function undefined?

  • 0
    Hello! Using the argument to which the function is passed, I call the function, which subsequently calls another function, which is already undefined for some reason, why so, and how to fix it?

    this.test(board, cards_obj, this.more, this.mores); // вызываем функцию test. P.S this.mores - это и есть функция, переданная в качестве аргумента.
    
    	test(board, cards_obj, button, func) {
    		button.addEventListener('click', (e) => {
    			if ( !button.classList.contains('inactive') ) {
    				func(board, cards_obj); // вызывается this.mores
    			}
    		});
    	}
    
    <b>this.mores:</b>
    
    mores(board, cards_obj) {
    		// Какой-то код
    
    		this.generate_cards(board.player, 1);
    
    // Какой-то код


    Error: Uncaught TypeError: Cannot read property 'generate_cards' of undefined

    P.S If the code in the test function is easy to insert, and not to collect by arguments, then everything will work.
    JavaScript Ryder Tucker, Feb 14, 2019

  • 1 Answers
  • 0
    You've lost this, it seems.

    Please give me a more complete code listing, I can tell you more precisely.

    Here it is generally not clear to you what these pieces are and what they refer to (some html tags inside the code, this is strange)
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!