I have a code like:
$.each($.parseJSON(data).content,function(){});
I would like to know if the $.parseJSON(data).content will be evaluated on each iteration, or just once? This will affect the performance significantly.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The arguments of a function call are always evaluated before the function is called. This isn’t jQuery specific. See the specification:
For clarity, this is not the case in
forloops:Here, the second expression is evaluated every time. This makes sense, since in a simple loop you want to reevaluate the condition
i < lengthat every iteration. But you don’t want to run$.parseJSONat every iteration. So inforloops, it does make sense to factor out the expression.