Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
markifornia

Chapter 8: Page 290 Referencing The Event Section

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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.

  • Upvote 3

Share this post


Link to post
Share on other sites

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;
   }
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...