var BounceBall = function() {
var ctx, W, H;
//对象中的对象
var init = function(id) {
var canvas = document.getElementById(id);
ctx = canvas.getContext('2d');
/*W = canvas.width || 600;
H = canvas.height || 400;*/
W = canvas.width ;
H = canvas.height;
this.circle(200, 300, 8);
this.rect(300, 300, 100, 50);
}
//给对象init添加属性:
init.prototype = {
clear: function() {
ctx.clearRect(0, 0, W, H);
},
circle: function(x, y, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
},
rect: function(x, y, w, h) {
ctx.beginPath();
ctx.rect(x, y, w, h);
ctx.closePath();
ctx.fill();
}
}
return init;
} ();
我想知道最后一行的“}”后面还加了个()是什么意思? 高手指教下,为什么这样用?谢谢,坐等
var ctx, W, H;
//对象中的对象
var init = function(id) {
var canvas = document.getElementById(id);
ctx = canvas.getContext('2d');
/*W = canvas.width || 600;
H = canvas.height || 400;*/
W = canvas.width ;
H = canvas.height;
this.circle(200, 300, 8);
this.rect(300, 300, 100, 50);
}
//给对象init添加属性:
init.prototype = {
clear: function() {
ctx.clearRect(0, 0, W, H);
},
circle: function(x, y, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
},
rect: function(x, y, w, h) {
ctx.beginPath();
ctx.rect(x, y, w, h);
ctx.closePath();
ctx.fill();
}
}
return init;
} ();
我想知道最后一行的“}”后面还加了个()是什么意思? 高手指教下,为什么这样用?谢谢,坐等
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货