weimingtom / minijoe

Automatically exported from code.google.com/p/minijoe
1 stars 0 forks source link

Prototyping not working within script. #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

var y = 10;
var x = 50;

function A() {
    this.text = "Hello";
    this.drawText = function() {
        context.fillStyle='black';
        context.translate(this.x+5,this.y+15);
        context.mozTextStyle="9pt bold Verdana";
        context.mozDrawText(this.text);
        context.translate(-1 * (this.x+5),-1 * (this.y+15));
    }

}

function B() {
}
B.prototype = new A();

b = new B();
b.drawText();

What is the expected output? What do you see instead?
Hello

What version of the product are you using? On what operating system?
Code from SVN

Please provide any additional information below.
Prototyping not working within script.

Original issue reported on code.google.com by Heinie.B...@gmail.com on 6 Sep 2009 at 5:35

GoogleCodeExporter commented 8 years ago
I have added this.x and this.y to function A() so that it will work within a 
browser
-----------------------
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

var y = 10;
var x = 50;

function A() {
    this.x=10;
    this.y=50;
    this.text = "Hello";
    this.drawText = function() {
        context.fillStyle='black';
        context.translate(this.x+5,this.y+15);
        context.mozTextStyle="9pt bold Verdana";
        context.mozDrawText(this.text);
        context.translate(-1 * (this.x+5),-1 * (this.y+15));
    }

}

function B() {

}
B.prototype = new A();

b = new B();
b.drawText();

Original comment by Heinie.B...@gmail.com on 6 Sep 2009 at 6:24