scope - Tips for an intermediate javascript programmer to write better code -
so i'm decent javascript programmer , i've finished working on big web application involved writing quite bit of javascript. 1 of things can across when debugging script there namespace conflicts various global variables used throughout script. essentially, javascript file structured such:
global var global var b global var c function1(){} function2(){} function3(){}
with jquery document on-ready function bind various events buttons in html , call functions event handler callbacks.
some people recommended encapsulating entire script in 1 gigantic function prevent scope-related errors. couldn't quite figure out entail. tips appreciated create web app involve quite bit of ajax page loads avoid browser refreshes , dom manipulation bound various events. thanks!
i recommend reading jquery plugin authoring guide (i recommend consider using jquery if not)
http://docs.jquery.com/plugins/authoring
btw been asked many times (not criticism re-asking)
- jquery: global variable namespace problem
- avoiding polluting global namespace javascript dependencies
- javascript namespace
i highly recommend read jquery live plugin register dom events(i guess built-in now): http://api.jquery.com/live/ (this minimize nasty need state management of unbinding , rebinding dom nodes).
Comments
Post a Comment