box = { curBox: 0, boxes: document.getElementsByClassName('box'), size: this.boxes.length, //this one won't work orSize: Object.keys(this.boxes).length, //as well as this one preBox: function() { curBox -= 1 }, nexBox: function() { curBox += 1 } } console.log(box.boxes.length); //This one works well!!! <div class='active box BG_blue'> <meta name='title' content='Overview' /> ... </div> <div class='inactive box BG_orange'> <meta name='title' content='Career' /> ... </div> <div class='inactive box BG_red'> <meta name='title' content='Skills' /> ... </div> <div class='inactive box BG_awesome'> <meta name='title' content='Hobbies' /> ... </div> I tried to get the length of an array returned from getElementsByClassName. If I put it outside the object range, it work. But inside the object range, it won't. Right now, I would like to know a reason how come. I've test on other site (such as Mozilla) code editor but it only return the same result.
thisdoesn't point to theboxobject.thispoints to the window object