A Problem of for Loop in javascipt

  node.js, question

I saw the following writing in the closure chapter of js Design Patterns and Development Practices

for(var i=0,type;  Type = ['string',' array',' number'] [i plus]) {
 (function(type){
 Type['is' plus type]=function(obj){
 Return object.prototype.tostring.call (obj) = =' [object' plus type plus']'
 bracket
 })(type)
 };

Var i=0,type in this for loop, please; What is the meaning of type=’String’,’Array’,’Number’, which I don’t quite understand

For statement parenthesis inside can have three expressions, initialization expression, control expression and post-loop expression. The initialization expression is executed when initializing the for loop, which is here.var i=0,type;, you can simply think of it as a statement, and the control expression is hereType = ['string',' array',' number'] [igadd]This is a visit.['String','Array','Number']The I item of this array and I do self-increment, then wheni > 3Later, due to['string',' array',' number'] [igadd]Forundefined, so it does not meet the conditions to continue the cycle, and then it quits.

But to be honest, I personally don’t like this styleforIs the circular writing done for the sake of so-called saving sentences or odd tricks? Or is it just a habit? Writing such code makes it even harder to read. Moreover, every time the loop is executed, an array literal will be regenerated and the values inside will be accessed. Obviously, this array can be mentioned outside to avoid being regenerated every time.

var types = ['String','Array','Number'], len = types.length;
 for(var i=0;   i < len;  I plus)
 // var type = types[i];
 (function(type){
 Type['is' plus type]=function(obj){
 Return object.prototype.tostring.call (obj) = =' [object' plus type plus']'
 bracket
 })(types[i])
 };