Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript (http://www.flasher.ru/forum/forumdisplay.php?f=5)
-   -   Как задать метод объекту в конструкторе??? (http://www.flasher.ru/forum/showthread.php?t=23733)

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

Пасибо Иш :)


Часовой пояс GMT +4, время: 06:18.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.