eko007
12-27-2011, 03:18 PM
Hello,
I'm trying to write my class with member properties and functions like below. What I want to learn is that is there any problem to use prototype object in the class that we want to use with it? I asked because I generally see that prototype object definition and member functions and properties created outside of the class unlike my class that I wrote like below.
Is there any problem writing my class like below?
Thanks.
function Point()
{
Point.prototype.x = this._x;
Point.prototype.y = this._y;
function _setX(x)
{
this.x = x;
}
Point.prototype.setX = _setX;
function _setY(y)
{
this.y = y;
}
Point.prototype.setY = _setY;
function _show()
{
alert(this.x + this.y);
}
Point.prototype.Show = _show;
}
function callMyClass()
{
var p = new Point();
p.setX(3);
p.setY(5);
p.Show();
}
I'm trying to write my class with member properties and functions like below. What I want to learn is that is there any problem to use prototype object in the class that we want to use with it? I asked because I generally see that prototype object definition and member functions and properties created outside of the class unlike my class that I wrote like below.
Is there any problem writing my class like below?
Thanks.
function Point()
{
Point.prototype.x = this._x;
Point.prototype.y = this._y;
function _setX(x)
{
this.x = x;
}
Point.prototype.setX = _setX;
function _setY(y)
{
this.y = y;
}
Point.prototype.setY = _setY;
function _show()
{
alert(this.x + this.y);
}
Point.prototype.Show = _show;
}
function callMyClass()
{
var p = new Point();
p.setX(3);
p.setY(5);
p.Show();
}