Javascript: Passing large objects or strings between function considered a bad practice

Posted by Mr. Smee on Stack Overflow See other posts from Stack Overflow or by Mr. Smee
Published on 2014-05-29T20:08:30Z Indexed on 2014/05/29 21:27 UTC
Read the original article Hit count: 249

Filed under:

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.

© Stack Overflow or respective owner

Related posts about JavaScript