• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

jQuery

 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been looking at jQuery for a week now and I like the way you can get lot of things done with a few lines / words!
The plugin mechanism is nice. But I have a concern. I find that the event handlers and callbacks are coded in-place like so -

$('.somediv').hello()
.bind("event1",function(){
//do something
}.bind("event2",function(){
//do something
});

OR

$('somediv').ajax(
onComplete:function(){

},
onError: someFunction
)

function someFunction(){

}


I would imagine in a larger application, this could lead to lot of procedural functions in the JS file. I was wondering how easy would it to be move these callbacks to may be a Javascript class or something and bind the event handlers to instance methods without a lot of work - I know that I can create a closure / something and delegate the call to the an object instance method.

What has been your experience working jQuery in this respect - developing apps with significant amount of JS/client code. How did you manage to keep related code together in jQuery. Did it make it harder to maintain?

I need some design patterns/ tips on developing large JS applications using jQuery.

We know what Struts / Spring MVC does to Java web applications - it tries to formalize a certain design pattern for developing 'server-side' java web applications. Has there been an attempt to roll out a similar framework on top of jQuery ? -
I mean a client side design pattern that will lead to maintainable code with jQuery / prescribed way of developing large JS heavy apps with jQuery.


thanks
Karthik






 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karthik Guru wrote:I find that the event handlers and callbacks are coded in-place like so -


While in-line functions are common in jQuery code, they are not required. This is, after all, normal JavaScript. Whether you provide an inline function or a function reference to a named function defined elsewhere is moot.

The inline mechanisms has a few distinct advantages, not limited to: taking advantage of closures, and not having to pollute the namespace with a bunch of bogus names for functions that will be referenced only once.

I would imagine in a larger application, this could lead to lot of procedural functions in the JS file


They've got to go somewhere. I'm not sure why you think this is an issue.

I was wondering how easy would it to be move these callbacks to may be a Javascript class


Well, there's no such thing as a JavaScript "class". But I know what you are talking about (a function bound to a constructed object instance.) And yeah, functions in JavaScript are first-class objects so you can refer to them either inline or as references as I mentioned above. it doesn't matter where the function is defined.

What has been your experience working jQuery in this respect - developing apps with significant amount of JS/client code. How did you manage to keep related code together in jQuery. Did it make it harder to maintain?


Not at all. In fact, I find the in-line function mehcanism makes the code quite compact and easy to figure out since everything is "right there".

I need some design patterns/ tips on developing large JS applications using jQuery.


Organizing your own code as jQuery plugins can go a long way to help keep the complexity managed.

We know what Struts / Spring MVC does to Java web applications - it tries to formalize a certain design pattern for developing 'server-side' java web applications. Has there been an attempt to roll out a similar framework on top of jQuery ? -


Really not necessary in my opinion.

I mean a client side design pattern that will lead to maintainable code with jQuery / prescribed way of developing large JS heavy apps with jQuery.


As mentioned above -- good code organization making liberal use of the jQuery plugin mechanism.

And good naming conventions, of course.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic