简体   繁体   中英

Confusion about callback concept in javascript and PHP

I'm a JavaScript developer and for server side I always do Node/Express. Now I'm learning to use Laravel but I'm running some confusions about callback concept.

For exemple: In Express when I do app.get('/myroute', function(req, res){...}) , the function(req, res) part is callback that will run after the serve receives the get request. In Laravel I have have something similar when using the routing system like when I do Route::get('/myroute', function(){...}) - I understand that the static method get of the Route class is executed but the function(){...} at the second parameter. So is that function also called "callback" like it the case for JavaScript? Is the event concept the same for the 2 programming languages?

The anonymous function in the Route::get('/myroute',function(){...}) is indeed a callback. PHP also calls those callables .

The event concept may or may not be used on either language. It's all about the context of each situation. This is true because callbacks can be used with our without the need of having an event.

Callback concept is the same in all programming language. Executing a function a get the return response as a parameter in your callback. What is a callback function?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM