English 中文(简体)
骨干:尿液法如何发挥作用?
原标题:backbone.js tutorial: how does the url method work?

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;
  }
});

我所努力的路线是:

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

最佳回答

这条线等于

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

仅凭return base+ / +this.id,即可得出一个包含base=”documents/“id=6的模型的“文件//6”。

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

return base+ / +this.id

例如,<代码>底线变量在同一栏目中界定。 然而,该法典也载于,主干法源代码,其宗旨如上所述。

而不是凌驾于<代码>url之上 您应制定以下方法:

var Document = Backbone.Model.extend({
  urlRoot :  documents 
});
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签