DISQUS

DISQUS Hello! Life is grand is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Functions as arguements

Started by paulmwatson · 10 months ago

Slash7 has posted the slides from their brilliant Javascript Boot Camp Tutorial talk at OSCON. 108 pages of pure JavaScript love. One thing I just learnt, on page 36, is that you can pass a function as an arguement into another function. That function can then call the arguement function. Sounds ... Continue reading »

3 comments

  • You can do that is C++ using function pointers and it's the same as Delegates in C#... you can pass a function into a function as a paramater and it can then call it etc.

    I think Java has something similar.
  • hi Paul --

    This is a reasonably common feature in dynamic languages like Perl, Python and Ruby.

    some of the things it allows are mindblowing; it gets even better when variable scoping is modified to allow "closures". You know the java pattern whereby you need to define an interface to receive a callback, then callers need to define instances of that interface etc. etc.? That becomes a single line of code in perl ;) it's truly beautiful in terms of simplification and readability.
  • What's even better is that you can return functions. Combined with closures, this results (for me) in a huge reduction in the need for big class hierarchies of simple classes, and drastically reduced the sort of cruft and namespace pollution that made me hate C++ so many years ago (a hatred that only diminished when i learned about templates).

Add New Comment

Returning? Login