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;

http://jsfiddle.net/x8jwavje/

 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)

edit: http://jsfiddle.net/x8jwavje/1/


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -