On 19 March 2012 16:29, Krinkle <krinklem...@gmail.com> wrote: > <ontopic :) > .. > > If you need non-linear keys, don't create an array! > > <code> > var myObj = {}; // not [] > myObj.property = value; > > var customProp = getPropName(); > myObj[customProp] = value; > > for ( var key in myObj ) { > // myObj[key] > } > </code> > > -- Krinkle
Suppose you want to use indexOf in a array. http://www.cjboco.com/blog.cfm/post/indexof-problems-in-internet-explorer/ So, lets use the power of JS to fix JS, .... lets add indexOf to the prototype http://stackoverflow.com/questions/948358/array-prototype-problem Ooops, Array.prototype is global var a = [1,2,3,4,5]; for (x in a){ // Now indexOf is a part of EVERY array and // will show up here as a value of 'x' } So what you do? you use a library for that. http://documentcloud.github.com/underscore/ http://api.jquery.com/jQuery.inArray/ $.each , _.each $.inArray, _.include( and a lot of other nice tools that make you happy. People seems to think functional programming is not something to avoid, but something that can be usefull. -- -- ℱin del ℳensaje. postdata: //TODO comment something about this var i=0;while(i<10) { print "hello";i++} for(var i=0;i<10;i++){ print "hello"} 10.times(function(){ print "hello"}); _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l