![]() ![]() ![]() OK, let's do it with Array now: let txt = "" Ĭonst person = īut let's try something, let's prototype something to Array. This statement will go up in the prototype chain, also enumerating over inherited properties, a thing that sometimes is not desired.Īlso, the order of iteration is not guaranteed by the spec., meaning that if you want to "iterate" an array object, with this statement you cannot be sure that the properties (array indexes) will be visited in the numeric order.įor example, in JScript (IE <= 8), the order of enumeration even on Array objects is defined as the properties were created: var array = Īlso, speaking about inherited properties, if you, for example, extend the Array.prototype object (like some libraries as MooTools do), that properties will be also enumerated: = function () Ĭonsole.log(txt) //Alireza Dezfoolian 35 The purpose of the for-in statement is to enumerate over object properties. The for-in statement by itself is not a "bad practice", however it can be mis-used, for example, to iterate over arrays or array-like objects.
0 Comments
Leave a Reply. |