How to get the correct this? for js

there is an object A:

function A(){
    this.Avar = "hello";
}
A.prototype.breadcrumb = {
    push: function(){
        console.info(this.Avar);
    }
};
var a = new A();

I want to add a breadcrumb object, using new A (). Breadcrumb.push , but the printed this is a {push:.} object, not a A object. How can I modify the context in which he reads the A object?

Mar.03,2021


function A(){

this.Avar = 'hello';
var self = this;
this.breadcrumb = {
    push:function(){
        console.log(self.Avar);
    }
};

}
var aa = new A ();
aa.breadcrumb.push ();

Menu