javascript - Why on earth is jack showing up in the sequence of alert boxes? -
object.prototype.jack = {}; var = [1,2,3]; for(var number in a){ alert(number); }
could tell me why word "jack" jumped out of alert box?
thank much!
simple - arrays objects in javascript adding:
object.prototype.jack={};
you've added enumerable property 'jack' objects (and arrays).
once creating array "a" , looping through of properties
for(var number in a)
you sure 'jack' alert. avoid showing can use .hasownproperty()
make sure alerted properties not inherited. or use regular
for(var i=0; < a.length; i++)
loop.
Comments
Post a Comment