试图从函数

时间:2017-10-30 08:03:12

标签: javascript

我一直试图让“hundredFunction()”在“gameCanvas”变量中输出为100%,其中“this.canvas.width = 100;”

我需要知道如何将“hundredFunction()”的输出声明为全局变量,以便我的“gameCanvas”变量不会被声明为“undefined”

我希望我能正确解释自己。提前感谢您的帮助。

(注意:我不需要知道这个的jQuery版本。)

// this loads the function tagged on the <body>
function startGame() {
    gameCanvas.start();
}

// this will allow us to 100% width and height of canvas
function hundredFunction() {
    var n = "100";
    var p = "%";
    var wh = n.concat(p);
    var hundred = wh;
}

var test = hundredFunction();
console.log(test);

// this will declare the variables to create the canvas on the <body>
var gameCanvas = { 
    canvas : document.createElement("canvas"),
    start : function() {
        this.canvas.width = hundred;
        this.canvas.height = hundred;
        this.context = this.canvas.getContext("2d");
        document.body.insertBefore(this.canvas, document.body.childNodes[0]);        
    }
}

1 个答案:

答案 0 :(得分:2)

您应该从Create table if not exists report1 ( col1 string, col2 string, col3 bigint )using parquet OPTIONS (path "/mnt/parent/") partitioned by (id,report="report1",date) 返回100%并使用此返回的var:

hundredFunction

此外,您不需要function startGame() { gameCanvas.start(); } function hundredFunction() { var n = "100"; var p = "%"; var wh = n.concat(p); return wh; // < Return your value } var hundred = hundredFunction(); // < Store it in a variable console.log(hundred); var gameCanvas = { canvas : document.createElement("canvas"), start : function() { this.canvas.width = hundred; // < Use it to your heart's content this.canvas.height = hundred; this.context = this.canvas.getContext("2d"); document.body.insertBefore(this.canvas, document.body.childNodes[0]); } } 功能来实现您的目标:

concat()
相关问题