Hi,
I have Image.js and Main.js files. I create image object like test = new Image(...);
and it can be seen on screen but when i try to do call Move method like
test.Move(x,y); it crashes. Is there anyway to do that?

My code :

main.js:

var objBall = new Image("abc.gif", 0, 0, visible);
objBall.Move(50,50);

image.js

function ImageDeneme(path, x, y, visible)
{
    this.image = document.createElement("img");
    this.image.src = path;
    document.body.appendChild(this.image);
    this.Move = Move;
    
    return this.image;
}

function Move(x, y)
{
    this.image.style.left = x + "px";
    this.image.style.top = y + "px";
}

waiting for your answers :)

i thing it should be like:

var objBall = new ImageDeneme("abc.gif", 0, 0, visible);

just use firebug to fine out what objBall. contains.

acctually i handle that problem and it works now but i have problem with inheritance now.

ImageClass.prototype = new Drawable(...);
ImageClass.constructor = ImageClass;

but i got "prototype is read-only" error. I'm working on a different platform but it supports javascript and as i got, it has different version of js.

could you tell how to inherit from a super class?

Genesistr,

Inheritance in JavaScript is a pretty large subject and in all probability not at all like what you're used to in other languages.

What ever else you read on the subject, you must read these - both by the master, Douglas Crockford:

Prototypal Inheritance in JavaScript
Classical Inheritance in JavaScript.

While you're about it, read everything you can by this guy and watch the videos:
http://javascript.crockford.com/

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.