Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:01+00:00 2026-05-26T18:25:01+00:00

tutorial: http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/ I am going through the CloudEdit rails/backbone.js tutrorial and got stuck on

  • 0

tutorial: http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/
I am going through the CloudEdit rails/backbone.js tutrorial and got stuck on the very first chunk of code. here it is:

var Document = Backbone.Model.extend({
  url : function() {
    var base = 'documents';
    if (this.isNew()) return base;
    return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
  }
});

the line I am struggling with is this

return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;

Since base = 'documents' isn’t base.charAt(base.length - 1) = s ?
I know what it is supposed to do, I am just wondering why it does it. Does the value of base change to documents/ sometimes? Why not just write return base+'/'+this.id

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:25:02+00:00Added an answer on May 26, 2026 at 6:25 pm

    That line is the equivalent of

    if last character is '/'
       return base + this.id
    else 
       return base + '/' + this.id
    

    just having return base+'/'+this.id would result in a url of “documents//6” for a model with base="documents/" and id=6

    Update
    As Adam Lassek mentioned in the comments, that line of should simply be written as

    return base+'/'+this.id
    

    for this example as the base variable is defined in that same block. However that line of code is also in the backbone.js source code and its purpose is as described above.

    Instead of overriding the url method you should set the urlRoot attribute in the model:

    var Document = Backbone.Model.extend({
      urlRoot : 'documents'
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I been going through this tutorial http://www.codeproject.com/KB/linq/BulkOperations_LinqToSQL.aspx and them make a SP like this
I went through this tutorial (http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html) and got everything working, only to find out
I am going through this tutorial http://www.9lessons.info/2009/04/exactly-twitter-like-follow-and-remove.html on how to implement a twitter-like follow/unfollow
I am running through a tutorial online at http://www.sthurlow.com/python/lesson08/ and I believe I understand
I'm working through this tutorial: http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-3.php At first he has you create a setter
I am following this tutorial: http://www.generation5.org/content/2001/sr00.asp?Print=1 Right off the bat it asks me to
I've followed the basic CherryPy tutorial ( http://www.cherrypy.org/wiki/CherryPyTutorial ). One thing not discussed is
I am following this tutorial: http://www.9lessons.info/2011/03/live-table-edit-with-jquery-and-ajax.html My addition is most content is ajax/json/dynamic. I
I just read the following section of the SWIG and Python tutorial: http://www.swig.org/Doc1.1/HTML/Python.html#n11 I
I am following the Ruby on Rails Tutorial for Rails 3, located here: http://ruby.railstutorial.org

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.