Javascript: Passing large objects or strings between function considered a bad practice
- by Mr. Smee
Is it considered a bad practice to pass around a large string or object (lets say from an ajax response) between functions? Would it be beneficial in any way save the response in a variable and keep reusing that variable?
So in the code it would be something like this:
var response;
$.post(url, function(resp){
response = resp;
})
function doSomething() {
// do something with the response here
}
vs
$.post(url, function(resp){
doSomething(resp);
})
function doSomething(resp) {
// do something with the resp here
}
Assume resp is a large object or string and it can be passed around between multiple functions.