开发者

What are some good practices when writing Javascript/jQuery code? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicates:

jQuery Standards and Best Practice

Javascript Best Practices

After finding that a website I wrote is leaking memory like crazy, I've started trying to improve the w开发者_如何转开发ay I write my Javascript/jQuery code.

For instance, instead of writing:

if ($('#elem').is(':checked'))

I can write:

if ($('#elem')[0].checked))

Directly interacting with the DOM rather than using jQuery as the middle man improves on speed, right?

As for memory leaks, should I consider jQuery callbacks to be like closures? If I reference an element in the callback, should I nullify the reference at the end of it's use? Or will the browser take care of that for me?

I'm just after some good tips to keep in mind when writing my code.


Run all your JS through JSLint

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜