DOM
-
use events delegation, instead of direct binding e.g. a table with 1000 rows, $("table").on("click", "tr", fn);
-
reduce reflow when changing DOM node 1. hide it first, then change, then display
-
clone it then change, then replace
/** | |
* Copyright 2012 Akseli Palén. | |
* Created 2012-07-15. | |
* Licensed under the MIT license. | |
* | |
* <license> | |
* Permission is hereby granted, free of charge, to any person obtaining | |
* a copy of this software and associated documentation files | |
* (the "Software"), to deal in the Software without restriction, | |
* including without limitation the rights to use, copy, modify, merge, |
Backbone provides us with a foundation to build the application. What it offers include:
models and collections
They encapsulate the business logic of the app and are in charge of the communication with the server.
views
They can be regarded as the controller in MVC architecture which manages display, user interaction and change of model's state. This is where data binding is happening between view and model.
events
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> |
.grid { | |
} | |
.cell { | |
background: black; | |
float: left; | |
box-shadow: inset 0 0 1px 0 white; | |
} | |
.cell.live { | |
background: seagreen; | |
} |
<html> | |
<head> | |
<title>Text Search</title> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> | |
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> | |
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> | |
</head> | |
<body> |
// mixin 1 | |
var SuperAbility = { | |
dance: function () { | |
console.log (this.name + " is dancing..."); | |
}, | |
talk: function () { | |
console.log ("talking from mixin..."); | |
} | |
} | |
// mixin 2 |
background: { | |
url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE8AAABPCAYAAACqNJiGAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NUVFREE2QTFENjc3MTFFMDg0RDg4QURBN0E4NTA4NTUiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NUVFREE2QTJENjc3MTFFMDg0RDg4QURBN0E4NTA4NTUiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpGNTQwMEVFNkQ1OTUxMUU |
var doopizlist = new DoopizCollection(); | |
doopizlist.fetch({ | |
success: function(collection ) { | |
console.log (collection); // see what's here ? | |
}, | |
error: function(doopizlist , error) { | |
console.log("error") | |
} | |
}); |
# active support library | |
# Active Support is the Ruby on Rails component responsible for providing Ruby language extensions, utilities, and other transversal stuff. | |
# It offers a richer bottom-line at the language level, targeted both at the development of Rails applications, and at the development of Ruby on Rails itself. | |
# http://guides.rubyonrails.org/active_support_core_extensions.html | |
# examples of functions | |
# blank? and present? |