Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created March 2, 2012 01:19
Show Gist options
  • Save elijahmanor/1954558 to your computer and use it in GitHub Desktop.
Save elijahmanor/1954558 to your computer and use it in GitHub Desktop.
Find the jQuery Bug #7: Solution
<label for="attendee-name">Attendee Name</label>
<input id="attendee-name" type="text"></input>
<button id="register" data-target="#attendee-name">Register</button>​
$( document ).ready( function() {
$( "#register" ).on( "click", function( e ) {
conference.register.apply( conference, [ e ] );
});
});
$( document ).ready( function() {
$( "#register" ).on( "click", function( e ) {
conference.register.call( conference, e );
});
});
var Conference = function( name ) {
this.name = name;
this.attendees = [];
};
Conference.prototype.register = function( e ) {
var $attendee = $( $( e.target ).data( "target" ) );
this.attendees.push( $attendee.val() );
alert( "Thanks for registering for " + this.name + ". " +
"There are " + this.attendees.length +
" registered thus far." );
$attendee.val( "" );
};
var conference = new Conference( "JavaScript Code Camp" );
$( document ).ready( function() {
$( "#register" ).on( "click",
$.proxy( conference.register, conference ) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment