Chetan Shah
Chetan Shah

Reputation: 129

Does a function gets invoked automatically

I have a function sendData(). My question is can it get executed without invoking it, inside the controller?

Upvotes: 0

Views: 67

Answers (2)

Jaanus
Jaanus

Reputation: 16541

No, but you can call it just after declaration.

var sendData = function() {
  //dostuff
}
sendData();

Upvotes: 1

Rahil Wazir
Rahil Wazir

Reputation: 10132

You can wrap your method in self execution name function.

var sendData = (function _() {
  // your stuff

  return _;
})();

It will directly executes and you can also later call it using sendData()

Upvotes: 1

Related Questions