Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

cleanup #1

Merged
1 commit merged into from

4 participants

Sven Lito Patrick Hall Emmanuel Medina Garcia Michal Valasek
Sven Lito

teaching people is one thing, teaching people how to write code that isn't clean is too easy, and isn't good teaching, right? ;)

Patrick Hall

It's good teaching. He's trying to learn Backbone, and a lot of other people are in the same boat and benefit from his effort to share. You found his project worth contributing to, so why are you simultaneously saying what he's doing is bad?

Emmanuel Medina Garcia

That´s true sometimes is better learning from a noob that may be at your leven than learning from a I know everything (svnlto) that already knows everything is going on and if they take their time to teach they usually do it with their elevated lenguaje manage that take you no where

Sven Lito

@amundo your missing the point.
@minardimedia did you actually look at the code to find out what has changed? what does "elevated language" mean anyways?

Michal Valasek

Could you please explain why did you move the external scripts linking from the head to the body? Why is it better like this? Thanks in advance!

Again: thanks a lot!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 30, 2011
  1. Sven Lito

    a bit of JS good practices..

    svnlto authored
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 40 deletions.
  1. +44 −40 examples/backbone-101/index.html
84 examples/backbone-101/index.html
View
@@ -2,51 +2,55 @@
<html>
<head>
<title>I have a back bone</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
- <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
- <script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
</head>
<body>
<button id="add-friend">Add Friend</button>
<ul id="friends-list">
</ul>
-<script type="text/javascript">
- $(function(){
- Friend = Backbone.Model.extend({
- //Create a model to hold friend atribute
- name: null
- });
- Friends = Backbone.Collection.extend({
- //This is our Friends collection and holds our Friend models
- initialize: function(models, options) {
- this.bind("add", options.view.addFriendLi);
- //Listen for new additions to the collection and call a view function if so
- }
- });
- AppView = Backbone.View.extend({
- el: $("body"),
- initialize: function(){
- this.friends = new Friends( null, { view: this });
- //Create a friends collection when the view is initialized.
- //Pass it a reference to this view to create a connection between the two
- },
- events: {
- "click #add-friend": "showPrompt",
- },
- showPrompt: function(){
- var friend_name = prompt("Who is your friend?");
- var friend_model = new Friend({ name: friend_name });
- //Add a new friend model to our friend collection
- this.friends.add( friend_model );
- },
- addFriendLi: function(model){
- //The parameter passed is a reference to the model that was added
- $("#friends-list").append("<li>" + model.get('name') + "</li>");
- //Use .get to receive attributes of the model
- }
- });
- var appview = new AppView
- });
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
+<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
+<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
+<script>
+(function ($) {
+
+ Friend = Backbone.Model.extend({
+ //Create a model to hold friend atribute
+ name: null
+ });
+
+ Friends = Backbone.Collection.extend({
+ //This is our Friends collection and holds our Friend models
+ initialize: function (models, options) {
+ this.bind("add", options.view.addFriendLi);
+ //Listen for new additions to the collection and call a view function if so
+ }
+ });
+
+ AppView = Backbone.View.extend({
+ el: $("body"),
+ initialize: function () {
+ this.friends = new Friends( null, { view: this });
+ //Create a friends collection when the view is initialized.
+ //Pass it a reference to this view to create a connection between the two
+ },
+ events: {
+ "click #add-friend": "showPrompt",
+ },
+ showPrompt: function () {
+ var friend_name = prompt("Who is your friend?");
+ var friend_model = new Friend({ name: friend_name });
+ //Add a new friend model to our friend collection
+ this.friends.add( friend_model );
+ },
+ addFriendLi: function (model) {
+ //The parameter passed is a reference to the model that was added
+ $("#friends-list").append("<li>" + model.get('name') + "</li>");
+ //Use .get to receive attributes of the model
+ }
+ });
+
+ var appview = new AppView;
+})(jQuery);
</script>
</body>
</html>
Something went wrong with that request. Please try again.