I found out I have two functions the share some some code so I decided to put it insied a template function:
function template(callback){
var all, these, variables, are, used, inthe, callbackFunction;
for (var i=0; i<10; i++){
callback();
}
}
function myFirstFunction(){
//do something with all those variables
}
function mySecondFunction(){
//do something else
}
So for each function I call template(myFirstFunction)
and template(mySecondFunction)
Is there any way I can use all variables defined in template function from my functions without passing them by parameter?
EDIT:
My functions are actually methods of an object:
function MyObject(){
};
MyObject.prototype.template = function(){
var all, these, variables, are, used, inthe, callbackFunction;
for (var i=0; i<10; i++){
callback();
}};
MyObject.prototype.myFirstMethod = function(){
this.template(function(){
//doSomething with all those variables
});
};
MyObject.prototype.mySecondMethod = function(){
this.template(function(){
//doSomething else
});
};