Title may not be correct but I didn't know how to ask my question!
I'm trying to learn writing Object-Oriented in JavaScript and I'm rewriting one of my projects so instead of lots of anonymous functions and duplicated codes I can use methods of classes. Now I'm facing an error on the following code:
var cart = {
cartModal: $("#cart-modal"),
$checkboxes: this.cartModal.find("input[name=check]"),
// ^^^^^^^^^^^^^^
toggleModal: function(e) {
this.cartModal.modal('toggle');
this.handleCheckboxes();
e.preventDefault();
},
handleCheckboxes: function() {
this.cartModal.find("input.checkall").click(function() {
$checkboxes.prop("checked", !$checkboxes.prop("checked"));
});
}
};
$("#cart-link").click(function(e) {
cart.toggleModal(e);
});
But I keep facing this error:
TypeError: this.cartModal is undefined
Should I use anything else to use an property inside an object? Or the problem lies somewhere else?