Uncaught TypeError: method is not a function

nikodeguzman

Code:

function Hotel(name,rooms,bookings){

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

    this.checkAvailability = function(){
        return this.rooms - this.bookings;
    }

    this.bookRoom = function(){
        if(this.checkAvailability() > 1){
            return this.bookings++;
        }
    }

    this.cancelBooking = function(){
        if(this.bookings < 1){
            return this.bookings--;
        }
    }
}


var grandHotel = new Hotel('Hotel Grand', 20, 5);
var addBooking = document.getElementById("book");

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

If I click the addBooking element I get this error:

Uncaught TypeError: this.checkAvailability is not a function.

epascarello

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Uncaught TypeError... no method 'on'

From Dev

jsPlumb setContainer method nonexistent: "Uncaught TypeError: undefined is not a function"

From Dev

Call Method from Constructor: Error: Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: Object function(a,b) has no method 'fancybox'

From Dev

Uncaught TypeError: Object (JS Function) has no method 'apply'

From Dev

Uncaught TypeError: $(...).stellar is not a function

From Dev

Uncaught TypeError: $.growl is not a function

From Dev

Uncaught TypeError: #<Object> is not a function

From Dev

Uncaught TypeError:Undefined is not a function

From Java

Uncaught TypeError: $.post is not a function

From Dev

Uncaught TypeError: $(...).tokenfield is not a function

From Dev

Uncaught TypeError: $(...).velocity is not a function

From Dev

Uncaught TypeError: $(...).ready is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: Object function

From Dev

Uncaught TypeError: number is not a function

From Dev

Uncaught TypeError: $(…).on is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

jQuery - Uncaught TypeError: $ is not a function

From Dev

Uncaught TypeError: $(...).autocomplete is not a function

From Dev

uncaught typeerror $(...).swipe is not a function

From Dev

Uncaught TypeError: $(...).draggable is not a function

From Dev

Uncaught TypeError: MyView is not a function

From Dev

Uncaught TypeError: response is not a function

From Dev

Uncaught TypeError: $(this).search is not a function

From Dev

Uncaught TypeError: lang is not a function

From Dev

Uncaught TypeError: undefined is not a function

From Dev

Uncaught TypeError: undefined is not a function

Related Related

  1. 1

    Uncaught TypeError... no method 'on'

  2. 2

    jsPlumb setContainer method nonexistent: "Uncaught TypeError: undefined is not a function"

  3. 3

    Call Method from Constructor: Error: Uncaught TypeError: undefined is not a function

  4. 4

    Uncaught TypeError: Object function(a,b) has no method 'fancybox'

  5. 5

    Uncaught TypeError: Object (JS Function) has no method 'apply'

  6. 6

    Uncaught TypeError: $(...).stellar is not a function

  7. 7

    Uncaught TypeError: $.growl is not a function

  8. 8

    Uncaught TypeError: #<Object> is not a function

  9. 9

    Uncaught TypeError:Undefined is not a function

  10. 10

    Uncaught TypeError: $.post is not a function

  11. 11

    Uncaught TypeError: $(...).tokenfield is not a function

  12. 12

    Uncaught TypeError: $(...).velocity is not a function

  13. 13

    Uncaught TypeError: $(...).ready is not a function

  14. 14

    Uncaught TypeError: undefined is not a function

  15. 15

    Uncaught TypeError: undefined is not a function

  16. 16

    Uncaught TypeError: Object function

  17. 17

    Uncaught TypeError: number is not a function

  18. 18

    Uncaught TypeError: $(…).on is not a function

  19. 19

    Uncaught TypeError: undefined is not a function

  20. 20

    jQuery - Uncaught TypeError: $ is not a function

  21. 21

    Uncaught TypeError: $(...).autocomplete is not a function

  22. 22

    uncaught typeerror $(...).swipe is not a function

  23. 23

    Uncaught TypeError: $(...).draggable is not a function

  24. 24

    Uncaught TypeError: MyView is not a function

  25. 25

    Uncaught TypeError: response is not a function

  26. 26

    Uncaught TypeError: $(this).search is not a function

  27. 27

    Uncaught TypeError: lang is not a function

  28. 28

    Uncaught TypeError: undefined is not a function

  29. 29

    Uncaught TypeError: undefined is not a function

HotTag

Archive