我想编写一个程序,当鼠标单击画布元素时显示一个矩形。我有某些模块,但不知何故,它们似乎没有连接。我在 JSFidle 中粘贴了没有命名空间的代码:
显示模块
(function(){
display = (function(){
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
return {
canvas: canvas,
context : context
}
})();
})();
管理器模块
(function(){
manager = (function(){
var canvas = display.canvas;
var context = display.context ;
var rect = function(){
ctx.fillRect(10,10,20,20);
}
return {
rect: rect
}
})();
})();
主模块
(function(){
canvas.addEventListener('mousedown', function(e) {
manager.rect;
}, 0);
})();