首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

Top 十 javascript

2012-08-15 
Top 10 javascriptLast but not least, a bonus function: The Prototype Dollar FunctionThis function s

Top 10 javascript
Last but not least, a bonus function: The Prototype Dollar FunctionThis function straight up kicks so much ass. First of all, just look at it.

Prototype function $
function $() {var elements = new Array();for (var i = 0; i < arguments.length; i++) {var element = arguments[i];if (typeof element == 'string')element = document.getElementById(element);if (arguments.length == 1)return element;elements.push(element);}return elements;}// Sample Usage:var obj1 = document.getElementById('element1');var obj2 = document.getElementById('element2');function alertElements() {  var i;  var elements = $('a','b','c',obj1,obj2,'d','e');  for ( i=0;i
Tell me that's not beautiful! Short not only by name, but by reference. It not only takes in strings, it takes objects too. You can pass it one argument, or pass it many! This by far is my favorite function of all time which will provide years and years of handiness.And so will they all...I hope this quick and handy list of JavaScript functions has been as useful for you as they have been for me. And for your downloading pleasure, here is all these functions wrapped up in a common.js just for you.After the factAdded after 30 comments or so...: Ok, I can understand everyone's point of view when it comes to 'these ten being the best'. The fact of the matter is, this is what I think were the best. If Dean Edwards wrote his top ten, I'm sure it would be different. If Stuart Langridge wrote his list, it too would be different. I mainly concentrated my list on the DOM. Browser detection is up to the developer at hand. Ajax functions I felt do not qualify as an 'all timer' mainly because Ajax is still in its infancy and has yet to impress me with something amazingly useful. For those wishing to just push these functions aside and slap on prototype to their documents, go ahead and slap on the extra 30k if you feel that's necessary. Nevertheless, thank you all thus far for the wonderful comments. I still hope this small list will come in handy for quite some time. And believe me, there are hundreds of other great functions that could possibly make it here. Just because it isn't here, doesn't mean it's not good. Just use your imagination ;)

热点排行