Created
March 2, 2012 01:19
-
-
Save elijahmanor/1954558 to your computer and use it in GitHub Desktop.
Find the jQuery Bug #7: Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label for="attendee-name">Attendee Name</label> | |
| <input id="attendee-name" type="text"></input> | |
| <button id="register" data-target="#attendee-name">Register</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $( document ).ready( function() { | |
| $( "#register" ).on( "click", function( e ) { | |
| conference.register.apply( conference, [ e ] ); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $( document ).ready( function() { | |
| $( "#register" ).on( "click", function( e ) { | |
| conference.register.call( conference, e ); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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