function Game(){
this.dom = document.querySelector('#canvas')
this.ctx = this.dom.getContext('2d')
this.R = {
'changge':'./images/wyyc.png',
'sea':'./images/xxdj.png',
'city':'./images/zfjg.png',
'zg':'./images/zg.png',
'ztly':'./images/ztly.png',
'xx':'./images/xx.png'
}
let imgUrl = Object.keys(this.R)
// console.log(imgUrl)
let allMount = imgUrl.length
let count = 0
let that = this
for(var i in this.R){
// 先备份地址
var src = this.R[i]
this.R[i] = new Image()
this.R[i].src = src
// 预存一份canvas
var self = this
console.log(self.start)
this.R[i].onload = function(){
count ++
self.ctx.clearRect(0,0,canvas.width,canvas.height)
self.ctx.font = '16px Arial'
self.ctx.fillText('图片已经加载了'+count+'/'+allMount+'张',10,50)
if(count == allMount){
self.ctx.drawImage(self.R['xx'],100,100,600,300)
}
}
}
}
// console.log(this.Game.prototype.start)
Game.prototype.start = function(){
// var self = this
// this.ctx.drawImage(this.R['xx'],300,300,100,100)
console.log(123)
}
// Game()
new Game()
很有可能是因为整个函数你并没有实例化,导致执行不了这个原型上的方法