PDA

Просмотр полной версии : Как задать метод объекту в конструкторе???


gOloVasTicK '~
28.11.2001, 22:29
function CScreen_getS(obj){
return obj.width*obj.height;
}
function CScreen (width, height) {
this.width = width;
this.height = height;
this.getS = CScreen_getS(this);
}


Не пашет :( Хелп плиз :(

ish
28.11.2001, 22:58
а что именно должно работать?

gOloVasTicK '~
28.11.2001, 23:03
Ну я хочу что-бы getS был методом класса CScreen
То-бишь:
screen=new CScreen(10,10);
trace(screen.getS()); // 100
screen.width=5;
trace(screen.getS()); // 100 а надо 50
:(

[subway]design
28.11.2001, 23:03
function Obj(){

function Method(param1, param2){
...
...
...
}

}
//****************************************
//or maybe this :
//****************************************

function Obj.Method(param1, param2){
...
...
...
}

ish
28.11.2001, 23:26
function CScreen (width, height) {
this.width = width;
this.height = height;
}

CScreen.prototype.getS = function() {
return this.width*this.height;
}

screen=new CScreen(10,10);
trace(screen.getS());
screen.width=5;
trace(screen.getS());

gOloVasTicK '~
28.11.2001, 23:29
Пасибо Иш :)