Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
Line 229: Line 229:


Another common technique to "overload" a function is to get a handle to the original function and then re-implement the function at your script's scope, so that calls to settimer/setlistener will automatically invoke your own version of the function, this is explained at [[Developing and debugging Nasal code#Managing timers and listeners]].
Another common technique to "overload" a function is to get a handle to the original function and then re-implement the function at your script's scope, so that calls to settimer/setlistener will automatically invoke your own version of the function, this is explained at [[Developing and debugging Nasal code#Managing timers and listeners]].
=== Storing Functions ===
Functions can also be easily stored in vector and/or hashes:
<syntaxhighlight lang="php">
var hash = {};
hash.hello = func {
print ("Hello !");
}
var vector = [];
append(vector, func {
print("Hello !");
});
##
# call the functions:
##
# the hash call:
hash.hello();
##
# the vector call:
vector[0]();
</syntaxhighlight>


===Functional programming, higher order functions, generators (advanced concept) ===
===Functional programming, higher order functions, generators (advanced concept) ===

Navigation menu