-2

I've used some callbacks in JS, I want to know how JS implements the callback mechanism. What is the principle of callback in JavaScript?

Thx.

xring
  • 727
  • 2
  • 8
  • 29
  • Right now, there must be like a dozen major JavaScript engines. You'll have to be more specific. – Álvaro González Sep 13 '15 at 16:25
  • @ÁlvaroG.Vicario thx a lot, next time my question will be more specific. As beginner in JS, I am just curious about how callback work. – xring Sep 13 '15 at 16:34
  • http://stackoverflow.com/questions/111102/how-do-javascript-closures-work?rq=1 , http://stackoverflow.com/questions/12930272/javascript-closures-vs-anonymous-functions - the answer sought will most likely be found in these questions. If not, please make sure a more speific question is asked. – user2864740 Sep 13 '15 at 16:36
  • @user2864740 thank you! – xring Sep 13 '15 at 16:38

2 Answers2

1

Functions are first class objects, thus they can be passed around like any other kind of object.

You pass a function as an argument to another function call, then you call it later.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

Just because functions are first-class objects, we can pass a function as an argument in another function and later execute that passed-in function or even return it to be executed later. This is the essence of using callback functions in JavaScript

maddygoround
  • 2,145
  • 2
  • 20
  • 32