Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

kako vratiti ime funkcije u as3

[es] :: Flash :: kako vratiti ime funkcije u as3

[ Pregleda: 2326 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

dblchckd
dbl chckd
zagreb

Član broj: 98011
Poruke: 8
*.adsl.net.t-com.hr.



Profil

icon kako vratiti ime funkcije u as302.01.2007. u 08:19 - pre 209 meseci
Kao da unutar funkcije dobijem njeno ime u as3? U as2 bi overrajdao toString funkciju:(primjer s http://chattyfig.figleaf.com/p...shcoders/2003-June/078663.html)
Code:
Function.prototype.toString = function(){
    return "[function "+this._name+"]";
};
_global.setFunctionNames = function(scopes){
    var i = 0, p;
    for (i; i<arguments.length; ++i){
        for (p in arguments[i]){
            if (typeof arguments[i][p] == "function") arguments[i][p]._name = p;
        }
    }
}

no wrappers or re-writing of your function definitions and its easy to turn 
off after the debugging is no longer needed (no use in having worthless 
function name variables if you only need them for debugging).  Depending on 
how many functions you have and how scattered their definitions are, the 
scope arguments might get a little lengthy, but its better than assigning 
the name for each function individually :)

Example:

function joe(){
    trace(arguments.callee);
}
bob = function(){
    trace(arguments.callee);
}
Class = function(){
    trace(arguments.callee);
}
Class.prototype.methodA = function(){
    trace(arguments.callee);
}
Class.prototype.methodB = function(){
    trace(arguments.callee);
}

setFunctionNames(this, Class.prototype);

joe(); // [function joe]
bob(); // [function bob]
instance = new Class(); // [function Class]
instance.methodA(); // [function methodA]
instance.methodB(); // [function methodB]

Kako problem rijesiti u as3? Ima li nacin da ne moram overrajdati toString()?
:?
 
Odgovor na temu

[es] :: Flash :: kako vratiti ime funkcije u as3

[ Pregleda: 2326 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.