javascript - How to pass a prototype function name to another prototype function -
this question has answer here:
function car() { } car.prototype = { update1: function(s) { console.log("updated "+s+" update1") }, update2: function(s) { console.log("updated "+s+" update2") }, update3: function(s) { console.log("updated "+s+" update3") }, update: function(s, updatefn) { this.updatefn.call(this, s) } } var c = new car() c.update("tyres", 'update1')
i want pass function name (update1 or update2 or update3) update function
output should : updated tyres update1;
function car() { } car.prototype = { update1: function(s) { console.log("updated "+s+" update1") }, update2: function(s) { console.log("updated "+s+" update1") }, update3: function(s) { console.log("updated "+s+" update1") }, update: function(s, updatefn) { this[updatefn]( s) } } var c = new car() c.update("tyres", 'update1')
this how should call function name passed parameter this[updatefn]( s)
Comments
Post a Comment