| View Poll Results: What do you use JavaScript and jQuery for mostly | |||
| Querying |
|
4 | 40.00% |
| Events |
|
5 | 50.00% |
| Attribute Manipulation |
|
3 | 30.00% |
| Style Manipulation |
|
5 | 50.00% |
| Ajax / Dynamic DOM |
|
8 | 80.00% |
| Multiple Choice Poll. Voters: 10. You may not vote on this poll | |||
|
|
|
|
Thread Tools | Search this Thread |
| 10-03-2012, 12:14 | #1 |
|
Registered User
![]() |
JavaScript / jQuery: Your most common uses
I'm just wondering the most common uses of JavaScript / jQuery in your day to day web development. I have a feeling myself that the most common feature is queries (as every other operation depends on queries). And if it is, how complex are your queries and why. (This is beyond simple document.getElementById) This can be a general JavaScript thread as well.
Last edited by Giblet; 10-03-2012 at 12:17. |
|
|
|
Advertisement
|
|
|
| 12-03-2012, 01:33 | #3 | |
|
Registered User
![]() |
Quote:
Javascript's object model, particularly it's esoteric and seemingly inconsistend this keyword, is a little confounding even to the JavaScript afficionado. jQuery allows you to always have a handy reference to what this would mean in a more object oriented context. Its DOM and AJAX stuff are nice, too, but mostly I use it because it's convenient. No more complex than they need to be. |
|
|
|
| 12-03-2012, 08:17 | #5 | |
|
Registered User
![]() |
Quote:
JavaScript has the following options. apply, call, bind and passing an object to act as a surrogate this. It's well documented. Functions in window scope have this = window. Calling in object scope makes this = the object. Apply, call and bind can assign these to whatever you wish. It's a context object. If your queries are not complex, why use Sizzle? Why not target either IE8+ with pure QSA? Or even get a smaller library such as NWMatcher which works better. All these engines use QSA anyway unless it's sub IE8, and they are painfully slow in those contexts. Use conditionals to load a query engine into sub IE8 and you've gotten rid of a lot of extra wasted space. Even better, don't write queries at all, learn how to traverse the DOM for your commons cases. Code:
<script>
var $;
if(document && document.querySelectorAll){
$ = function(selector){ return document.querySelectorAll(selector);}
}
</script>
<!--[if lte IE 8]>
<script src="myEngine.js"></script>
<script>
$ = function(selector){ return myEngine.Query(selector); }
</script>
<![endif]-->
Last edited by Giblet; 12-03-2012 at 09:30. |
|
|
|
|
Advertisement
|
|
|
| 12-03-2012, 08:32 | #6 |
|
Registered User
![]() |
It's not my attitude that's meant to be helpful. The code will suffice. Anyway, I'll dig less into jQuery, I really just want to highlight how to get things done in a concise manner with the least amount of script necessary.
Last edited by Giblet; 12-03-2012 at 08:37. |
|
|
| 12-03-2012, 09:35 | #7 |
|
Booooom, Blast & Ruin
![]() |
most recently, it's been used for handlebars.js templates to help with heaps of repeating data and reducing the amount of unnecessary and redundant code being created with the help of handlebars helpers.
precompiled templates sent to the user on first visit to the site, 10k json responses sent via ajax after that is quite efficient. |
|
|
| 12-03-2012, 09:38 | #8 | |||||
|
Registered User
![]() |
Quote:
Quote:
this will not. Quote:
Yes, and thank the binary digital gods it does. Quote:
I use jQuery, not its spin-off project Sizzle. And I use jQuery for to make javascript suck less. I thought I was quite clear on that. Because I don't write Internet Explorer applications. I don't even use Windows to develop. Quote:
Seriously, I see an awful lot of personal opinion that doesn't address why I use jQuery at all. Quite frankly I'm not sure I should be listening to your advice on JavaScript development at all. |
|||||
|
|
| 12-03-2012, 09:40 | #9 |
|
Registered User
![]() |
|
|
|
|
Advertisement
|
|
|
| 12-03-2012, 09:48 | #10 | ||||||||
|
Registered User
![]() |
Exactly. You double wrap it in some cases.
this is not an object?. What do you mean by your next quote then? Quote:
Code:
typeof this Depends on context though, but it's not special in any case. If you want a discussion on Host Objects, Props & Methods and the dangers of doing typeof's though... Quote:
Quote:
Code:
var bind;
if(Function.prototype.bind){
bind = function(fn, thisObject) {
return fn.bind.apply(fn, Array.prototype.slice.call(arguments, 1));
};
}
else {
if(!!Function.prototype.call) {
bind = function(fn, context) {
var prependArgs = Array.prototype.slice.call(arguments, 2);
if (prependArgs.length) {
return function() {
fn.apply(context, Array.prototype.concat.apply(prependArgs, arguments));
};
}
return function() {
fn.apply(context, arguments);
};
};
}
}
Quote:
Quote:
Quote:
Quote:
Quote:
Also, my personal opinion doesn't matter. Ask the right questions, I'll give you the answers if you need. jQuery is not a context driven API, so if you need one, you need to write it yourself. If you don't, fine! People who might need one. Mobile Application developers. Low Powered Devices. Adding a huge library isn't going to help. People on shared hosting deliverin 90k (no gzipping on many shared hosts) scripts to mobile devices that won't cache the data might want a solution. If you don't need this, then why continue to bash Answer the poll if you'd like though. Last edited by Giblet; 12-03-2012 at 11:56. |
||||||||
|
|
| 12-03-2012, 10:25 | #11 | |
|
Registered User
![]() |
Quote:
Last edited by Giblet; 12-03-2012 at 10:33. |
|
|
|
| 12-03-2012, 10:29 | #12 | |
|
Registered User
![]() |
Quote:
That's about 2k of script, or 15k if you need to get a query selector engine in there which in fairness is mostly for older IE (still under the iphone limit and about 4k if you count gzip which iPhone doesn't unfortunately). If it's obscure, I'm sorry, but can you see the point of what I'm doing at least? You might not do the sort of development that needs granular scripting to improve performance, which is lucky! Last edited by Giblet; 12-03-2012 at 10:33. |
|
|
|
| 14-03-2012, 19:18 | #13 |
|
Registered User
![]() |
No, I use jQuery because it makes DHTML generation on the fly (particuarly regarding binding events) easier to cross platform. It gives a consistent, cross platform, reference to the calling object. I like its XHR wrapper. I use its Tree walking abilities in processing returned XML.
I'd say I use about 60-80% of jQuery's functionality, project dependant. |
|
|
| 14-03-2012, 19:52 | #14 |
|
Registered User
![]() |
Event delegation for dynamic DOM is trivial, it's taken until 1.7 for jQuery to have a unified method of doing so. Again, creating a consistent, cross platform reference to the calling object is also trivial. You just write a wrapper to handle forking for different browsers (I mean, jQuery can't do anything JavaScript can't do). Fair enough about the XHR wrapper, although they've gone and changed that again. And DOM is a pretty simple node list to traverse, which is handy for XML. Although jQuery can mess this up with expando properties and should never be used for XML if you are serious into accurate processing of properties (jQuery will in some cases create new properties on the fly just by calling .attr / .data but you could do this yourself anyway if you didn't know what properties your XML had)
Again, you have use for jQuery, I want to talk about how to get to the root of what people need rather than throwing the kitchen sink at a problem. I think I can help with that. Last edited by Giblet; 14-03-2012 at 19:59. |
|
|