Created
November 9, 2011 14:53
-
-
Save mxriverlynn/1351655 to your computer and use it in GitHub Desktop.
Backbone, Object Literals, View Events, jQuery and `el`
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
| <div id="someElement"> | |
| <button id="someButton">Click Me</button> | |
| </div> |
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
| MyView = Backbone.View.extend({ | |
| el: $("#someElement"), | |
| events: { | |
| "click #someButton": "clicked" | |
| }, | |
| clicked: function(e){ | |
| e.preventDefault(); | |
| alert("I was clicked!"); | |
| } | |
| }); |
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 myViewDefinition = { | |
| el: $("#someElement"), | |
| events: { | |
| "click #someButton": "clicked" | |
| }, | |
| clicked: function(e){ | |
| e.preventDefault(); | |
| alert("I was clicked!"); | |
| } | |
| }; | |
| MyView = Backbone.View.extend(myViewDefinition); |
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
| myObj = { | |
| foo: "some value", | |
| bar: 1 + 1 | |
| }; |
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
| function add(a, b){ | |
| return a + b; | |
| } | |
| myObj = { | |
| bar: add(1, 1) | |
| } |
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(){ | |
| // your code here | |
| }); |
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
| $(function(){ | |
| // your code here | |
| }); |
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
| $(function(){ | |
| MyView = Backbone.View.extend({ | |
| el: $("#someElement"), | |
| events: { | |
| "click #someButton": "clicked" | |
| }, | |
| clicked: function(e){ | |
| e.preventDefault(); | |
| alert("I was clicked!"); | |
| } | |
| }); | |
| }); |
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
| MyView = Backbone.View.extend({ | |
| events: { | |
| "click #someButton": "clicked" | |
| }, | |
| initialize: function(){ | |
| this.el = $("#someElement"); | |
| }, | |
| clicked: function(e){ | |
| e.preventDefault(); | |
| alert("I was clicked!"); | |
| } | |
| }); | |
| $(function(){ | |
| var myView = new MyView(); | |
| }); |
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
| MyView = Backbone.View.extend({ | |
| events: { | |
| "click #someButton": "clicked" | |
| }, | |
| clicked: function(e){ | |
| e.preventDefault(); | |
| alert("I was clicked!"); | |
| } | |
| }); | |
| $(function(){ | |
| var myView = new MyView({ | |
| el: $("#someElement"); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment