Skip to content

Instantly share code, notes, and snippets.

View bittersweetryan's full-sized avatar

Ryan Anklam bittersweetryan

View GitHub Profile
app.ContactCollection = Backbone.Collection.extend({
model : Contact,
initialize : function(){
var self = this;
this.fetch({
success : function(){
self.trigger("load");
}
app.ContactCollection = Backbone.Collection.extend({
model : app.Contact,
initialize : function(){
this.fetch();
},
url : 'contacts/'
});
app.NewView = Backbone.View.extend({
initialize : function(){
this.addContacts();
},
addContacts : function(){
_.each(app.contacts.models, function(val, key){
//add them to a drop down
});
initialize : function(){
app.contacts.on("load",$.proxy(this.addContacts(),this));
}
function getMessages(name){
return $.Deferred(function(dfd){
var messages = [];
// static messages
messages.push("Hello " + name);
messages.push("Thank you for stopping by.");
var eventHandlers = {
name : 'Home Simpson',
clickHandler : function(){
console.log('hello: ' + this.name);
}
};
$("a").on('click',eventHanlers.clickHandler);
$("a").on('click',eventHanlers.clickHandler);
@bittersweetryan
bittersweetryan / gist:3488243
Created August 27, 2012 13:02
jQuery Deferred
$.when(
func1(),
func2(),
func3()
).then(...)
@bittersweetryan
bittersweetryan / gist:3488387
Created August 27, 2012 13:25
jQuery Deferrds
var func1(num){
return $.Deferred(function(dfd){
if(typeof num !== 'number'){
dfd.reject('not a number');
}
else{
dfd.resolve(num);
}
}).promise()
}
@bittersweetryan
bittersweetryan / gist:3488409
Created August 27, 2012 13:31
jQuery Deferrds
var func1(num){
var dfd = $.Deferred();
if(typeof num= !== 'number'){
dfd.reject('not a number');
}
else{
dfd.resolve(num);
}