I have a lot of functions that currently look like this:

function LoadFromURL(url) 
{
    var d = $.Deferred();
    $.get(url).then(function(text)
    {
        LoadFromText(text).then(function(obj)
        {
            d.resolve(obj);
        }, 
        function(err)
        {
            d.reject(err);
        });
    }, 
    function(err)
    {
        d.reject(err);
    });
    return d.promise();
}


This function takes a URL and loads the text within a promise. The text is then passed to the LoadFromText function which returns another promise. If this succeeds, the outer deferred is resolved. If the URL cannot be loaded, or the LoadFromText function fails then the outer deferred is rejected.

Is there a way that I can chain the result of the resolve / reject and end up with something like this:

function LoadFromURL(url) 
{
    return $.get(url).then(function(text)
    {
        return LoadFromText(text);
    }, 
    function(err)
    {
        return $.Deferred().reject(err);
    }).promise();
}


I've seen some implementations of promises that allow this - returning a promise within 'then', means that the eventual result of the promise is used. 

I realise this doesn't work at the moment (the result is the promise, rather than the result of the promise), but hopefully someone can suggest a way to make this work so I can tidy up the sometimes confusing mess of the first example.

I hope this makes sense. Thanks.


Question: What are the benefits of owning a physical book?
Answer: This easily reads as a matter of preference to me over anything.  From a subjective standpoint I simply enjoy the smell of ink and paper and the feel of pages but from there... It's anyone's race really.

E-Books


Portability: The only reason I bring a laptop or e-reader to games is usually because the game is when I'm playing at the home of someone else or a neutral location of some sort.  Call me lazy, but I'm less than enthused to carry my entire collection which with my AD&amp;D stuff, is easily a dozen each hardback and soft cover books.  Having digital copies saves me some potentially considerable effort to keep everything I need with me.  Every game I have been a part of for any serious duration usually has several books and everyone needs only one or two pages from the extras but the whole book has to come along.
Indexing:  There are precious few books that have a pervasive index.  Some are simply maddening because they will place an entry as a subsection of another instead of being its own listing.  Searchable text has been a life saving feature that helps me even facilitate answers for this site because I can keep jabbing the "find next" button to make sure there isn't some hidden passage of errata in a different section of the book.  I can go directly to what I want.  Not only this, but I have a dyslexic player who uses the e-book to read aloud to him and that's the only way he learns the rules without a walkthrough mid-game.
Errata: Some releases are digital only nowadays.  Books can always be scanned for free, but new digital content costs to be printed (even if minutely... at first) and having a file is a resource that can be given back.  Unless you choose to print on both sides (or use the back of an already printed page) that page is spent.  Maybe line a birdcage with it but that's about it once you're done.


Spined Books


Redundancy:  Murphy is my worst player.  He corrupts files, drops books and readers alike, summons unholy deluges that permeate the stoutest bag as I dart from vehicle to building.  A book can take a fair amount of damage before becoming useless.  Even if it gets wet or torn, the other pages are still viable.  A backup of files is cheap and easy but a backup of devices is frustratingly costly.  Even if one book becomes totally useless, the rest should still be in good condition anyway.
Psychology: I can't agree more with PlasmaHH when it was stated that genuine books imply something about the DM/GM/ST.  They usually mean business unless it's that rich friend who can piddle away money for books like they're tissue boxes.  Every game I've been in where the DM is serious about their world, the content, and grasp of the rules they never subsumed on PDFs alone (although certainly had them where possible).  It's kind of like the illusion a gym membership provides where by virtue of having spent good money on something, you want full value of the resource and hardback books are the most costly.  Other than systems that went out of print before I was aware of them, everything I run I keep at least a core book hard copy for communal use if nothing else.
Distribution: Probably beating a dead horse with many of the answers explaining how using a genuine book means you can give media away without losing the entire medium to read it.  However with some companies being notorious for bad binding, I've seen books split into binder volumes and individual pages given tot he players who need them and right back in the pot when they're done.  No entry cost of time to find the right file, download, change storage device/upload to cloud, download to new device, open, find again for a one time use.  Just give the page back when you're done.
Wear &amp; Tear Can be Your Friend: Believe it or not, the more a book is used, the more useful it gets in my experience.  Several of my books have been opened and creased to specific pages I use so often that with a blind grab at the right depth of the volume I can open to the exact page I want to something I may not have thought to leave a bookmark on (digitally or literally).  Typically any system's combat turn order, the start of its magic and skill sections become permanently held for intuitive indexing.


Equality/Trading Off


Annotation: Familiarity breeds ease of use.  I can place sticky notes or add comments with equal proficiency, as well as remember the page number (within ten pages) or randomly open to it in the book by approximate depth.  These functions are synonymous to me because essentially they work the same by keeping custom information.  In a hard copy you have limited space and might lose a sticky note or tucked index card where in an e-book you might have to guess where the comment trigger is to be found since it collapses.
Multiple Pages: As a subjective factor, being able to separate books and pages to be larger than a screen's resolution can accurately display helps me do the work faster.  However!  Using a laptop for almost all of my digital reading, I have been known to make a second copy of the core book in the folder so I can hold two pages simultaneously open in the same book without creating a conflict.  I have on many occasions held three or four books open and traversed them as easily as my books splayed like scalemail when the situation called for it.
Visibility: For hard copies of books the resolution is almost always perfect.  It matches the size of the viewer (IE the book's physical size) and thus you can always see a full page at the proper reading size.  While the viewing area is often limited on e-readers (I'm rarely displeased with monitors/laptops) the ability to zoom is surprisingly useful, especially for farsighted gamers.  Granted, you can zoom with a mundane magnifying lens on a hard copy as well.  But ultimately both methods fulfill the need equally to me objectively.  I can shrink a window and hold two completely different sources side by side concurrently when not using an e-reader specifically for PDFs.
Space: Being able to keep a library in a device the size of a 9v battery is quite handy... But where did you put that book on it?  Unless you're a database generating fiend such as myself, you probably just have a big mess of books in one spot with no sorting method in place, which when you're looking at a series of identical icons can get tiresome.  Sure hard copies take up space and weight but the visual indexing is powerful as is the mnemonic device of having to sort them as they go on the shelf (if you're even half as compulsive as me when it comes to books) and have at least two senses tied to their shelving - seeing the book slide into space, touching the book (as at least to me different publishers feel different in the slightest ways), maybe even smelling the book as you do.  However, searchable indexing on most devices tends to alleviate this issue which is why it shows up in the "both" category instead of as a distinct advantage.