Although this question has nothing to do with VB6 and RC5, I'm learning and using JS with the thinking of an old VB6 user, so I still want to put it in the VB6 sub-forum. I'd like to hear the opinions from Olaf, jpbro and other JS experts.
Original thread: A strange JavaScript code
I saw a piece of JavaScript code and I thought it was a bit weird.
I understand this code this way: box is a function object(class), and variable myBox is an instance of the box object(class). But the myBox variable appears inside the box, which makes me feel a bit strange.Code:var myBox = new box(); function box() { this.dx = 0; this.dy = 0; this.test = function(a, b, c){ var div = box.test2(a, b, c); if (div) { myBox.dx = 400; myBox.dy = 600; } } this.test2 = function(a, b, c) { ... ... } }
Is this usage of myBox appropriate? Will skilled or sophisticated JavaScript developers write code in this way? Is there a better way to achieve similar functionality? Thanks.




Reply With Quote