The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 06:45:08 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: jQuery  (Read 2399 times)
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2879



View Profile
« on: June 16, 2010, 10:38:20 PM »

http://www.drdobbs.com/java/201000935;jsessionid=QNP5I4SQRJO2LQE1GHPCKH4ATMY32JVN

For some reason this nicely written Dr Dobbs jQuery article caused my head to happily explode, probably because I hadn't realized the magnitude of the JavaScript headache savings.  Issuing a statement such as:

$("div")

and causing all <div> statements to be instantly wrapped for manipulation just rules.  Part of my mental blockage was perhaps how I've always seen wrapper classes in the past: cool, powerful, and often times a pain in the ass when all you really need is X, not a few pages of Y pass-through code that you have to roll by hand.

Here's to jQuery  Applause
Logged

I would love to change the world, but they won't give me the source code.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: June 16, 2010, 11:35:30 PM »

Yeah man, it's the juice. There are several things that i still manually because they're faster, but some things in jQuery are just so damn strong there's no equal.

I am particularly fond of writing completely non-intrusive code that binds to elements in the HTML rather than inline ... Stuff that can execute a behavior or event vector on anything that has a classname of(x) for example. Really powerful stuff.

One should be careful not to over rely, because it can add some significant processing overhead to a page, but it is DAMN worth your time to grok.

IM with a tiny URL example on the way ...
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #2 on: June 17, 2010, 02:33:52 AM »

With jQuery $('<div>') and $('div') just scratches the surface. There's way, way more powerful stuff inside like chaining, delegating, selecting parents/children etc. But with jQuery it's also easy to shoot yourself in the foot. Like do a whole webservice with $.live and $(':input') type of selector use and you got yourself a crawling and lagging clusterfuck. Also without understand DOM and crap related to that it's just too easy to use each and then $(elem).appendTo('#div') in every iteration.
Logged

I met god and he had nothing to say to me.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #3 on: June 17, 2010, 02:41:11 AM »

I just noticed that there's some old advices in that article. For example with noConflict() you don't need to do var $j = jQuery; .. just do:
Code:
jQuery.noConflict();
(function($) {
  $(function() {
   .. your code ..
  });
})(jQuery);

Now you can still use $ in your code without conflicting other libraries.. yeah, I'm looking at you Mootools..
Logged

I met god and he had nothing to say to me.
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« Reply #4 on: June 17, 2010, 04:44:18 AM »

I want tiny URL secret email examples too!!!

$(selector).action()

here are two great references:


http://www.w3schools.com/jquery/trysel.asp?filename=trysel_basic&jqsel=p.intro,%23choose

http://www.w3schools.com/jquery/jquery_ref_selectors.asp


Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: June 17, 2010, 08:38:09 AM »

Also without understand DOM and crap related to that it's just too easy to use each and then $(elem).appendTo('#div') in every iteration.
EXACTLY. jQuery can, in many ways, be a replacement for thinking and understanding the DOM. And it is no speed demon, so care must really be taken.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2879



View Profile
« Reply #6 on: June 17, 2010, 10:05:10 AM »

It seems like a good friend though for someone like me who violently resists heavy, client-side solutions where browser incompatibilities and code maintenance concerns chill the bones of even the most adventurous of coders.  The monotony of JavaScript along with the terrible choices people have made where everything seems like

mark up
code
markup
markup
code
code
markup
codeup
markode
code...


But if performance were my main concern I'd bite the bullet in those areas and make sure the code was optimized (or hire someone to do this Smiley).  I think JavaScript is to me like Java is to nuts  ROFLMAO
Logged

I would love to change the world, but they won't give me the source code.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #7 on: June 17, 2010, 10:45:45 AM »

Also without understand DOM and crap related to that it's just too easy to use each and then $(elem).appendTo('#div') in every iteration.
EXACTLY. jQuery can, in many ways, be a replacement for thinking and understanding the DOM. And it is no speed demon, so care must really be taken.
Yeah, just to clarify that DOM is no speed demon but jQuery is speed demon. With 1.4.2 release it's the fastest javascript framework around beating even Dojo 1.4.1.

I highly recommend checking Paul Irish's slideset about jQuery performance guidelines at http://www.slideshare.net/paul.irish/perfcompression

In my opinion javascript is the most misunderstood language and after I have been reading and coding with it, it has become my favorite language along Ruby. It's just so different because it doesn't work like languages I have been programming before. Like for example anonymous functions and being able to do weird shit like like var run = (new Function("return "+code))();

With Opera 10.6 and IE9 all browsers support web workers, javascript will soon perform things you wouldn't believe.
Logged

I met god and he had nothing to say to me.
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2879



View Profile
« Reply #8 on: June 17, 2010, 11:14:47 AM »

I like this one...

Quote
The Zen of Python

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than right now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!


    —Tim Peters
Logged

I would love to change the world, but they won't give me the source code.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!