function car() {
}
car.prototype = {
update1: function(s) {
console.log("updated "+s+" with update1")
},
update2: function(s) {
console.log("updated "+s+" with update2")
},
update3: function(s) {
console.log("updated "+s+" with update3")
},
update: function(s, updateFn) {
this.updateFn.call(this, s)
}
}
var c = new car()
c.update("tyres", 'update1')
I want to pass a function name (update1 or update2 or update3) to update function
output should be : updated tyres with update1;
http://jsfiddle.net/x8jwavje/
function car() {
}
car.prototype = {
update1: function(s) {
console.log("updated "+s+" with update1")
},
update2: function(s) {
console.log("updated "+s+" with update1")
},
update3: function(s) {
console.log("updated "+s+" with update1")
},
update: function(s, updateFn) {
this[updateFn]( s)
}
}
var c = new car()
c.update("tyres", 'update1')
this is how you should call a function whose name passed as a parameter this[updateFn]( s)
Edit: http://jsfiddle.net/x8jwavje/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With