Uncaught TypeError: method is not a function

前端 未结 1 1688
离开以前
离开以前 2021-01-23 02:57

Code:

function Hotel(name,rooms,bookings){

    this.name = name;
    this.rooms = rooms;
    this.bookings = bookings;

    this.checkAvailability = function(){         


        
1条回答
  •  孤城傲影
    2021-01-23 03:27

    You need to change how the event is being bound.

    addBooking.addEventListener('click', grandHotel.bookRoom.bind(grandHotel), false);
    

    or

    addBooking.addEventListener('click', function() { grandHotel.bookRoom(); }, false);
    

    0 讨论(0)
提交回复
热议问题