2014-07-03 54 views
0

我在做一個使用coffeescript的項目。在實例中,盡​​管沒有理由,但似乎結束了一個功能。我也使用d3,因此所有這些函數鏈都可能是編譯器失敗的原因。還是我失去了一些東西爲什麼coffeescript在它應該結束之前結束我的功能

此:

render3Circles = (pageName) -> 
    dataset = [ 
     Math.random() 
     Math.random() 
     Math.random()] 
    svg = d3.select("#"+pageName) 
     .append("svg") 
     .attr("width", "400") 
     .attr("height", "400") 
    # add arcs + tip circles 
    arcs = svg.selectAll("path") 
     .data(dataset) 
     .enter() 
     .append("path") 
    tipCircles = svg.selectAll("circle") 
     .data(dataset) 
     .enter() 
     .append("circle") 
    tipCircles.attr("fill", (d,i) -> 
      colors[i] 
     ) 
     .attr("cx", (d, i) -> 
      100 
     ) 
     .attr("cy", (d, i) -> 
      150 
     ) 
     .attr("r", arcWidth/2) 
    arcs.attr("d", drawArc) 
     .attr("fill", (d,i) -> 
      colors[i] 
     ) 
     .attr("class", "arc-path")     # assigns a class for easier selecting 
     .attr("transform", "translate(200,200)") # sets position--easier than setting x's and y's 
     .attr("d", drawArc) 
    svg.attr "style", "opacity:0.5;margin-top:20px;" 

編譯成這樣:

render3Circles = function(pageName) { 
    var arcs, dataset, svg, tipCircles; 
    dataset = [Math.random(), Math.random(), Math.random()]; 
    svg = d3.select("#" + pageName).append("svg").attr("width", "400").attr("height", "400"); 
    arcs = svg.selectAll("path").data(dataset).enter().append("path"); 
    tipCircles = svg.selectAll("circle").data(dataset).enter().append("circle"); 
    return tipCircles.attr("fill", function(d, i) { 
    return colors[i]; 
    }).attr("cx", function(d, i) { 
    return 100; 
    }).attr("cy", function(d, i) { 
    return 150; 
    }).attr("r", arcWidth/2); 
}; 

arcs.attr("d", drawArc).attr("fill", function(d, i) { 
    return colors[i]; 
}).attr("class", "arc-path").attr("transform", "translate(200,200)").attr("d", drawArc); 

svg.attr("style", "opacity:0.5;margin-top:20px;"); 

之前,我開始畫弧的功能正好結束。如果我切換圓弧和圓的一部分,它也會做同樣的事情。

CoffeeScript的版本:1.6.1 Ubuntu的服務器12.04

+0

你有一些縮進問題,不能用你給我們的代碼複製,它編譯得很好:http://bit.ly/1lWZHCc。考慮用兩個空格替換製表符來縮進。 – meagar

+0

我曾試過。它也適合我在線編譯。只是不在我的Ubuntu服務器上。 Coffeescript版本:1.2.0。命令:coffee -cb。 (編輯:我剛剛意識到,我的coffescript版本已過時。brb正在升級......) –

+0

Err,好吧,1.2.0差不多3歲。考慮升級。 – meagar

回答

0

我通過updateing節點和NPM,然後安裝咖啡腳本的最新版本(1.7.1當時)

我希望糾正這個錯誤用這個答案我可以爲他節省幾個小時。 (從github安裝節點需要一些時間,我過了一晚)