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
你有一些缩进问题,不能用你给我们的代码复制,它编译得很好:http://bit.ly/1lWZHCc。考虑用两个空格替换制表符来缩进。 – meagar
我曾试过。它也适合我在线编译。只是不在我的Ubuntu服务器上。 Coffeescript版本:1.2.0。命令:coffee -cb。 (编辑:我刚刚意识到,我的coffescript版本已过时。brb正在升级......) –
Err,好吧,1.2.0差不多3岁。考虑升级。 – meagar