Optional Parameters - Extending Existing Functions
Both PHP and javascript allow optional parameters and variable arguments.
PHP
- func_get_args() - allows you to get the arguments for a function. Great if you need a variable number of arguments, perhaps for something like sprintf. http://us3.php.net/manual/en/function.func-get-args.php
- Default arguments - allows you to set a default value for an argument. This also effectively makes the argument optional, since if it isn’t passed, the function won’t crash. Important if you have to add something to a function without disrupting existing code that calls it. http://us3.php.net/manual/en/functions.arguments.php#functions.arguments.default
javascript
- The arguments sent to a function in javascript can be accessed as function_name.arguments. To find out how many arguments were passed, you can use function_name.arguments.length. http://www.w3schools.com/jS/js_functions.asp
- Implementing default arguments with javascript can be done by using the arguments array.
Print article | This entry was posted by elvis on 04/14/09 at 08:33:14 pm . Follow any responses to this post through RSS 2.0. |