Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript : what does it mean to have brackets () after array[]?

Tags:

javascript

I am new to JS, and I have read a code that contains this line.

this.myArray[index](this._sender, args);

I wonder what it means?

like image 466
NASHEN Avatar asked Sep 22 '26 05:09

NASHEN


1 Answers

It means that this array item is a function, and it is being called with arguments this._sender and args.

In this example, I declare an array, push a single-argument function to it, and call it.

var arr = [];

arr.push(function(str) {
  document.body.innerHTML = "Hey, " + str;
});

arr[0]("Your name");
like image 138
Yeldar Kurmangaliyev Avatar answered Sep 23 '26 18:09

Yeldar Kurmangaliyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!