some of these code I understand but "{}" what does this mean...??
var Accordion = function(el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
// Variables
var link = this.el.find('.link');
// Eventos
link.on('click', {el: this.el, multiple: this.multiple},this.dropdown)
}
{}
in this context means an empty Javascript object (the same as new Object()
) with no custom properties or methods on it.
So, this statement:
// if el contains a value, do this.el = el, otherwise init this.el to an empty object
this.el = el || {};
is logically equivalent to this:
if (el) {
this.el = el; // initialize from function argument
} else {
this.el = {}; // initialize to an empty object
}
Or in words, "if el
contains a non-empty/non-null truthy value, then assign it to this.el
otherwise, initialize this.el
with an empty object".
It is a shortcut notation to initalize a variable with the first one in the list that is truthy because Javascript's ||
operator evaluates until it finds the first truthy operand and then stops the evaluation and takes that operand as the value.
It means a JavaScript object with no methods or properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With