A class has an and b function,a calling b. Visit a now, how to get the name? of an in b

as described in the question, how to implement

in each language

has been reported to the Shoushou Party! It is said that the hand-holding party or the problem is too stupid, but it does not explain the specific reason?

Mar.13,2021

PHP can be obtained using debug_backtrace .


javascript:

class Foo {
    a() {
        console.log('call func b');
        this.b();
    }
    b() {
        console.log(this.a.name);
    }
}

1:
class Foo {

function a(){
    var name = '';
    b(name);
}
function b(var name){
    console.log(name);
}

}

Menu