javascript - why does the got view is undefined in construct function? -
why got view undefined in construct function ?
i set in define, set in function arguments, still undefined, view returned object.
here view must got:
define([ 'jquery', 'backbone', 'resources', 'views/ship', 'models/ship', 'models/stage' ], function ($, backbone, resources, shipview, shipmodel, stagemodel) { var stageview = backbone.view.extend({ tagname: 'canvas', id: 'stage', classname: 'stage', model: stagemodel, initialize: function () { this.listento(stagemodel, 'change', this.move); this.ctx = this.el.getcontext('2d'); resources.load(['images/space1.jpg']); }, render: function() { this.el.width = $('body').width(); this.el.height = $('body').height(); this.model.xpos = 1500 - (this.el.width / 2); this.model.ypos = 1500 - (this.el.height / 2); return this; }, move: function (model) { }, motion: function () { } }); return new stageview(); });
here view must one:
define([ 'jquery', 'backbone', 'resources', 'views/stage', 'models/ship' ], function ($, backbone, resources, stageview, shipmodel) { var shipview = backbone.view.extend({ tagname: 'canvas', id: 'ship', classname: 'ship', model: shipmodel, initialize: function () { console.log(stageview); //---- undefined this.ctx = this.el.getcontext('2d'); resources.load(['/images/ship.gif']); this.el.width = $('body').width(); this.el.height = $('body').height(); this.model.setcenter({ x: this.el.width / 2, y: this.el.height / 2 }); this.shippos = { x: this.el.width / 2 - 35, y: this.el.height / 2 - 35 }; this.inmove = false; this.loaded = false; }, events: { 'click': 'move', 'mousemove': 'mousemove' }, render: function () { var = this; resources.onready(function () { that.loaded = true; that.image = resources.get('/images/ship.gif'); that.ctx.translate(that.el.width / 2, that.el.height / 2); that.ctx.drawimage(that.image, -35, -35, 70, 70); }); return this; }, move: function (event) { this.model.setclickcoords({ x: event.pagex, y: event.pagey }); this.rotate(event); this.inmove = true; }, movedone: function () { alert("asd") this.inmove = false; }, mousemove: function (event) { if (!(this.inmove) && this.loaded) { } }, rotate: function (event) { } }); return new shipview(); });
in console.log stageview undefined, why ? please need help
Comments
Post a Comment