面向对象练习题

第一个

 1 window.onload = function(){
 2     var Game = function(canvas , options){
 3         var _options = options || { width : 300 , height : 300 }
 4         var _pos = {x : _options.width / 2 , y : _options.height}
 5         canvas.onmousemove = function(e){
 6             _pos = {
 7                 x : e.clientX / 2 ,
 8                 y : e.clientY / 2
 9             };
10             init();
11         }
12         function init(){
13             canvas.style.width = _options.width + 'px';
14             canvas.style.height = _options.height + 'px';
15             canvas.style.left = _pos.x + 'px';
16             canvas.style.top = _pos.y + 'px';
17         }
18         init();
19         this.conTent("不在本方法内,调用一下");
20     }
21     Game.prototype.conTent = function(msg){
22         console.log(msg);
23     }
24     var canvas = document.getElementById('canvas');
25     new Game(canvas);
26 }
原文地址:https://www.cnblogs.com/piaozhe116/p/5512350.html