Dynamic names of functions in javascript:
In some conditions we are in need of dynamic function names.
In js we can do this by creating classes.
for e.g.
var surgeonVal = 1; // value for id
function surgeonPagination() {
$('.nav-next').click(function (e) { // next button clicked
var result = Class.callFunc(surgeonVal);
surgeonVal++;
});
}
var Class = (function (window) {
return {
1: function () {
//Do some work
},
2: function () {
//Do some work
}
},
3: function () {
//Do some work
},
callFunc: function (funcName) {
return this[funcName]();
}
};
})(window);
In this above example I want to call some functions as accordingly to change value of "surgeonVal". So I create a class and call it's function as accordingly.
Thanks
In some conditions we are in need of dynamic function names.
In js we can do this by creating classes.
for e.g.
var surgeonVal = 1; // value for id
function surgeonPagination() {
$('.nav-next').click(function (e) { // next button clicked
var result = Class.callFunc(surgeonVal);
surgeonVal++;
});
}
var Class = (function (window) {
return {
1: function () {
//Do some work
},
2: function () {
//Do some work
}
},
3: function () {
//Do some work
},
callFunc: function (funcName) {
return this[funcName]();
}
};
})(window);
In this above example I want to call some functions as accordingly to change value of "surgeonVal". So I create a class and call it's function as accordingly.
Thanks
No comments:
Post a Comment