在类原型中调用另一个原型函数

时间:2014-06-21 15:57:24

标签: javascript

我有一个名为" viewport"的类原型,就像这样(它真的很长,所以只是片段)

function Viewport(Container) {
    this.x = 0;
    this.y = 0;
    this.w = 0;
    this.h = 0; 
...

然后在某些时候我有这个

    this.Draw = function() {
        this.Canvas.width = this.w;
        this.Canvas.height = this.h;
        cDrawGrid(this.ctx, this.x, this.y, this.w, this.h, this.scale);
        //add other draw calls later
    }

更进一步,我得到了这个

    this.onMouseMove = function(e) {
        if (!this.bMoving) return;
        e = getEvent(e);
        this.x += e.clientX - this.LastMouseX;
        this.y += e.clientY - this.LastMouseY;
        this.LastMouseX = e.clientX;
        this.LastMouseY = e.clientY;
        this.Draw();
    }

它不起作用,但是Opera错误控制台说"类型错误:this.Draw()不是函数"

为什么会这样?

0 个答案:

没有答案