3

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 way 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.

4
  • 1
    possible duplicate of jQuery Standards and Best Practice, Javascript Best Practices, Object Oriented Javascript best practices?,... Commented Aug 18, 2010 at 3:04
  • I'll take a look at those threads now. Thanks for the links. Commented Aug 18, 2010 at 3:11
  • Of course the 2nd example is faster than the first. Anyways. For good practices are you talking about speed or readability? Commented Aug 18, 2010 at 3:30
  • Speed. I'll be the person handling the code so I don't have to worry about someone else getting confused trying to follow what it's doing. Commented Aug 18, 2010 at 3:34

1 Answer 1

0

Run all your JS through JSLint

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.