Calling one prototype method inside another in javascript

后端 未结 1 1525
粉色の甜心
粉色の甜心 2020-12-02 19:36
var Ob = function(){


}

Ob.prototype.add = function(){
    inc()

}

Ob.prototype.inc = function(){
    alert(\' Inc called \');

}

window.onload = function(){
va         


        
相关标签:
1条回答
  • 2020-12-02 20:16

    It's easy:

    Ob.prototype.add = function(){
        this.inc()
    }
    
    Ob.prototype.inc = function(){
        alert(' Inc called ');
    }
    

    When you create the instance of Ob properties from prototype are copied to the object. If you want to access the methods of instance from within its another method you could use this.

    0 讨论(0)
提交回复
热议问题