开发者

In Javascript/jQuery, is there a difference in rendering performance if I condense my code into "one-liners"?

Is there a difference in performance (I am not asking about readability) if I condense my code into one line versus two?

For example:

var slide = 'images/' + n + '.png';

$('img').attr('src',slide);

versus

$('img').attr('src','images/' + n + '.png');

Personally, I like fewer lines o开发者_如何学编程f code. Often, I am the only one reading my code, so communicating intent is not as important.

I am curious if the Javascript interpreter executes one of the above options faster (even though this is a classic micro-optimization example).


No difference in rendering performance, at all.


Micro-optimization doesn't half say it. :-)

The answer will depend a lot on the interpreter involved. I wouldn't be surprised if IE's interpreter had a very very very very very very (...continue saying "very" for a while...) very slight, impossible to detect difference. Chrome's V8, on the other hand, is certain not to.

In real terms, though? No, no difference at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜