Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 496847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:43:29+00:00 2026-05-13T05:43:29+00:00

I am having trouble settling down to a proper practice for UI JavaScript coding.

  • 0

I am having trouble settling down to a proper practice for UI JavaScript coding. So I am looking for a smarter way to do things. I’ve been using jQuery with ASP.NET and I have been doing things like below which seems unprofessional and dumb. JavaScript UI programming has always been a mysterious to me. I know how to do it but I never knew how to do it properly.

$(function(){
    $('submit').click(function() {
        //behaviors, setup styles, validations, blah...
    });
});

Problems:

  • Code duplications are often therefore harder to maintain and reuse
  • With ClientIds are generated by ASP.NET, it’s hard to pull code chunks into separate js files
  • Common declarations are placed on master pages, however jQuery document ready function appears almost on every other pages as well

Goals:

  • JavaScript library/framework independent, so that it will be easier to switch frameworks down the road
  • Encapsulate/modulate logic for easy reuse, so that on each page, it will only be a few simple lines of initialization code
  • Separation of concerns for easy maintenance and readability

Questions:

Being a C# developer mainly my thinking is very OO and jQuery is very procedural. I understand the concepts of Anonymous Function however in general my mind is still trying to make a domain model which abstracts the UI then declares properties or methods. But I am really not sure if this is the way in JavaScript. Or am I being too ideal or am I trying too hard to make something that’s not supposed to be OO OO like? So the questions are:

  • Should I start to encapsulate/modulate functions using JavaScript prototype and make it a bit more OO like? So that HTML controls or behaviours can be encapsulated for reuse?
  • Or should I start encapsulate logics into jQuery plug-in? But this way the code will be 100% dependent on jQuery.
  • Or any other approaches?

Thank you.

Updated:
I just found this slide and it seems to be a good starting point.
This is also a good example that I just found. And a good tutorial by the creator of jQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:43:30+00:00Added an answer on May 13, 2026 at 5:43 am

    The best technique I have found for code reuse, dealing with client ids and so on is to intoduce a more object oriented approach into my Javascript.

    This has the following benefits

    1. Easier to introduce scoping and multiple instances of the same thing on the same page
    2. Easier to manage client id farce

    I still use Jquery within this.

    So to give an example if I had a javascript based widgit I wanted to make use of I would create an “object” called widget and save it in a Widget.js file. The widget object would have instance variables, a constructor and public, private methods just like in any other OO langauge e.g Widget.js would look like

    // constructor
    function Widget(aFooId,bBarId)  
    {
     // instance variables  
     var fooId = aFooId;  
     var barId = bBarId;  
    
     // some magic to expose public methods  
     this.Init = Init;  
    
     // public methods  
     function Init()  
     {  
       alert("called init");  
     } 
    
     //private methods  
     function PrivateMethod()  
     {  
    
     }  
    
    }  
    

    The call on the aspx page would look like

    var widgetInstance = new Widget("<%=Foo.ClientId%>",<%=Bar.ClientId%>);
    widgetInstance.Init();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery UI Selectmenu and am having trouble setting the value of
I am having some trouble settling on a way to represent a structure that
I've been having trouble setting a textarea element's width and using padding via CSS.
I'm using D3.js and I'm having trouble setting up a stacked layout for an
I'm having some trouble implementing a fixed table header with CSS and jQuery, though
Im having Trouble setting up an in memory database using RavenDB. The error I
I'm having trouble setting up a new server using Moonshine and Capistrano. It seems
I am having trouble setting a property of a custom user control using a
I am having trouble setting the path to jquery in an mvc app. In
We're having trouble setting window captions using cyrillic or japanese characters. We either see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.