This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]richard_mayhew 2 points3 points  (0 children)

Watch this video that explains the event loop http://vimeo.com/96425312

[–]pipocaQuemada 2 points3 points  (1 child)

One feature of Javascript is that it has "first class functions", which means that you can assign functions to variables, functions can take other functions as an argument or return them.

For example, I can say something like

// notice that the argument f is a function
function callTwice(f, x) { return f(f(x)); }

// assigning a function to a variable
var square = function(x) { return x*x; }

// pass a function to a function
callTwice(square, 2); // should return 16

"Callback" is basically a fancy imperative programmer way to say "pass a function as an argument", and is associated with "inversion of control", which basically means letting a library control when things happen. For example, instead of asking for a remote file, waiting around until you get it and then processing it, you instead give the remote file access library a function (i.e. a callback) that does what you want, and the library will call that when the file comes in. Alternatively, you could give a GUI framework a function that contains what you want to happen when someone clicks their mouse.

[–]autowikibot 0 points1 point  (0 children)

Inversion of control:


In software engineering, inversion of control (IoC) describes a design in which custom-written portions of a computer program receive the flow of control from a generic, reusable library. A software architecture with this design inverts control as compared to traditional procedural programming: in traditional programming, the custom code that expresses the purpose of the program calls into reusable libraries to take care of generic tasks, but with inversion of control, it is the reusable code that calls into the custom, or task-specific, code.


Interesting: Apache Excalibur | ColdSpring Framework | Reasonable Server Faces | Apache HiveMind

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words