jquery - javascript prototype loop for in array -


i working on project, use lot of "javascript". have lot of "ajax" calls, returns à "json" array. usefull reasons, created 2 prototypes of array object ("in_array" function , "shuffle" function).

since did prototypes, "for in" loops broken (two times showing "undefined" ...) looked google , stackoverflow, , know mistake now. of course, if delete prototypes, "undefined" go away.

but, don't find answers.

first, see lot of times, using "for in" loops bad, why ?

i develop in "php" or "python" too, , do love "for in" or "foreach" loops.

secondly, got lot of "for in" loops, honnestly prefer changing prototypes, changing loops. dirty switch prototypes normal functions, , keep "for in" loops ?

thirdly, read jquery can correct bug. project did got jquery, solution talking (i read jquery can correct this, not how).

thank you,

edit : prototypes code :

// fonctions array array.prototype.shuffle = function () { (var = this.length - 1; > 0; i--) {     var j = math.floor(math.random() * (i + 1));     var tmp = this[i];     this[i] = this[j];     this[j] = tmp; }  return this; }  array.prototype.in_array = function (needle) {     for(var = 0; < this.length; i++) {        if(this[i] == needle)            return true;     }     return false; } 

here map function like. wrote out of top of head there may bugs.

function object_map(object, callback) {     var key, ret = {};     (key in object) {         if (object.prototype.hasownproperty.call(object, key)) {             ret[key] = callback(key, object[key]);         }     }     return ret; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -