Mootools when using For(…in Array) problem

后端 未结 3 1641
无人及你
无人及你 2021-01-19 07:56

This problem been there for couple years.

I am writing some plugins for a Forum engine called Discuz, I use a lot of Mootools for my own projects. When I plug Mootoo

3条回答
  •  轮回少年
    2021-01-19 08:20

    Mootools extends Array.prototype and maybe even Object.prototype, which can interfere with for .. in loops, which enumerate all properties, even those that exist in the object because they appear upwards on the prototype chain. Therefore, test if the property is a direct property of the object before using it:

    for(i in a)
        if (a.hasOwnProperty(i))
            console.log(i);
    

提交回复
热议问题