javascript - Presentational js vs. functional js: Separate them? General architecture? -
This is a common type of question
Many times, I have to type javascript for the web page. Keeping in mind the best practices, Vineet JS etc. I have my javascript in different * .js files. I found my JS file for each page. What was bothering me lately, this is a mix of current code with functional code that I always end up with. Therefore, for example, I will provide an .click
handler to an element. On that click the element should change its appearance and make an AJMX call on the server. So, now, I want to put both of these inside the .click
handler. It can be heavy depending on what is required to fulfill it when I come back after touching these blocks for a week, I think that when I only need to see some things, then I think it takes too much time through all the codes.
Thank you!
I have to put them together, which is related to the events that they were removed, but never -Only put a function to call things to a particular group's things. Example:
function domyUIstuff (myevent, myselector) {// stuff here}; Function domyBehaviorStuff (myevent, myselector) {// dostfiler}; $ (Selector) Click (function (e) {domyUIstuff (e, $ (this)); domyBehaviorStuff (e, $ (this));}
Side note: I do different users Different stuff from controls (I do a lot of ASP.N. content) - I create a myusercontrol.js file for myusercontrol.ascx as well as my mypage.asp file for mypage.aspx Cut down "noise" when I debug - I put my "generic" functions in the page file, which I myself Controls can make calls like normal AJAX message handlers or normal "utility" functions.
Comments
Post a Comment