markifornia Posted October 29, 2012 Share Posted October 29, 2012 Again, another simple question but this one is regarding the example in the book as follows: function someEventHandler(e) { // use e. } The text says "Often the argument is abbreviated as just e or evt, short for event." Are "e" and "evt" reserved keywords? Or is the text just saying that "e" and "evt" are used commonly as the argument? Any argument could have been used such as "x" and "y", correct? Link to comment Share on other sites More sharing options...
HartleySan Posted October 29, 2012 Share Posted October 29, 2012 e and evt are not reserved words. The parameter could be anything (including x and y, as you suggested). 1 Link to comment Share on other sites More sharing options...
markifornia Posted October 29, 2012 Author Share Posted October 29, 2012 coolio, thanks Hartley Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 30, 2012 Share Posted October 30, 2012 You'll see this often in programming if the function uses well known functionality. It's much clearer with parameter hinting as you get the object type to. It's also more common if classes implement well-known interfaces to get functionality. Below is an example from Java that allows to to get input from a mouse. These types of interfaces can include 15-20 methods, so you would spare a lot of code by just using Event e. class MouseInput implements MouseListener { public void mouseClicked( MouseEvent e ) { } public void mouseEntered( MouseEvent e ) { } public void mouseExited( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { } public void mouseReleased( MouseEvent e ) { } } AnyEvent e is pretty much standard naming for events, as is Graphics g, Comparator cmp or Iterator itr. These of course differ slightly in difference languages, etc, but are pretty general well known names for the functionality they provide. These names are not "standards" by any stretch of the imagination, though, so feel free to use what you like. 3 Link to comment Share on other sites More sharing options...
markifornia Posted October 30, 2012 Author Share Posted October 30, 2012 excellent antonio! I like the idea of parameter hinting Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 30, 2012 Share Posted October 30, 2012 Remember that you can do so in PHP with arrays and objects too. class User {} // A simple, empty class class UserList { private $users = array(); // Can only add Users to the list public function add( User $u ) { $this->users[] = $u; } } Link to comment Share on other sites More sharing options...
Recommended Posts