如何围绕require js函数编写定义包装器

时间:2020-07-18 16:49:43

标签: highcharts requirejs durandal

我想将以下代码包装为定义方法


var c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;

c1=c2=c3=c4=c5=c6=c7=c8=c9=c10=0;

var counters= [c1,c2,c3,c4,c6,c6,c7,c8,c9,c10];



for (var i=0;i<counters.length;i++){
    fill(0, 0, 0);
    textSize(25);
    text(counters[i],10+40*i,50); 
//this text function does show the updated counter variable, it stays on 0. Why?
    line(i*40,0,i*40,400);
}




stroke(38, 165, 224);
fill(255, 255, 255);
rect(140,231,120,43);
textSize(25);
fill(0, 0, 0);
text("Play again", 141,258);
mouseClicked= function(){
if (mouseX<150+120 && mouseX>154 && mouseY>231 &&mouseY<231+43){
var randomx=random(0,400);
ellipse(randomx,100,20,20);
if (randomx>=0 && randomx<40){
    c1++;
    println(c1);
} else if(randomx>=40 &&randomx<=80){
c2++;
println(c2);
}
}
};

我使用durandal SPA。所以我需要一种定义方法来从其他地方进行校准。

1 个答案:

答案 0 :(得分:1)

最简单的解决方案是将require替换为define

        define([
            'highcharts',
            'highcharts/modules/exporting',
            'highcharts/modules/accessibility'
        ], function (Highcharts) {
            Highcharts.chart('container', {
                series: [{
                    data: [1,2,3,4,5]
                }]
            });
        });
相关问题