javascript - suppress main function call with function defined in prototype -
have @ code below:
function person() { this.fname = 'baby'; this.lname = 'boy'; this.walk = function () { return 'i can walk'; } } person.prototype.walk=function(){ return 'all can walk';} var obj=new person(); obj.walk();
now want let both these funtions in code want when make call walk using obj.walk()...it should calling walk function prototype,as result return me 'all can walk'
you can delete obj.walk
remove property specific object, , force use inherited method.
function person() { this.fname = 'baby'; this.lname = 'boy'; this.walk = function () { return 'i can walk'; } } person.prototype.walk=function(){ return 'all can walk';} var obj=new person(); delete obj.walk; console.log(obj.walk());
Comments
Post a Comment