This file contains 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
// jQuery - failures persist along the chain | |
$.Deferred(function(d) { d.reject() }) | |
.then(function() { console.log("Success handler 1") }, function() { console.log("Fail handler 1") }) | |
.then(function() { console.log("Success handler 2") }, function() { console.log("Fail handler 2") }); | |
// Output: | |
// Fail handler 1 | |
// Fail handler 2 | |
// ------------------------------------------------------------------------------------------------------ |
This file contains 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
define('mod/bbsync', [ | |
'underscore' | |
, 'mod/ajax' | |
], function(_, Ajax) { | |
function sync(method, model, options) { | |
var url = model.url, data | |
url = _.isFunction(url) ? model.url() : url | |
data = method === 'create' || method === 'update' | |
? model.toJSON() : {} |
This file contains 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
JSWEEKLY BINGO | |
+-------------------------------+-------------------------------+-------------------------------+ | |
| An atricle from someone who | | | | |
| just figured out | Baby's first functional | How to do this one very | | |
| prototype-based OO and thinks | programming | specific thing in Node.js | | |
| everyone else needs telling | | | | |
+-------------------------------+-------------------------------+-------------------------------+ | |
| | | | | |
| A new jQuery release | A job in San Francisco | An introduction to an MVC | | |
| | | framework | |
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.
This file contains 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 stringify = function(obj, prop) { | |
var placeholder = '____PLACEHOLDER____'; | |
var fns = []; | |
var json = JSON.stringify(obj, function(key, value) { | |
if (typeof value === 'function') { | |
fns.push(value); | |
return placeholder; | |
} | |
return value; | |
}, 2); |
This file contains 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 isPrimitive = function(val) { | |
return val !== function() { return this; }.call(val); | |
}; |
This file contains 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
// all this `toJSON()` does is filter out any circular refs. all other values/refs, | |
// it passes through untouched, so it should be totally safe. see the test examples. | |
// only extend the prototype if `toJSON` isn't yet defined | |
if (!Object.prototype.toJSON) { | |
Object.prototype.toJSON = function() { | |
function findCircularRef(obj) { | |
for (var i=0; i<refs.length; i++) { | |
if (refs[i] === obj) return true; | |
} |
With the lastest version of Require, a new config object was introduced, the shim
.
http://requirejs.org/docs/api.html#config-shim
That allows Amplify to now be used within AMD projects.
Have Fun!