Hello,
I just came to the object part in JavaScript, which is the instance of the object can be iterated by the for-loop (or with-loop):
function Car(seat_sth, engine_sth, radio_sth) {
this.seats = seat_sth;
this.engine = engine_sth;
this.radio = radio_sth;
}
var work_car = new Car("Leather", "V-6", "Cassette/Disc");
for (var propname in work_car) {
document.write(propname + ": " + work_car[propname] + "<br>")
}
Instead of iterating an instance of the object, is there a way to have object constructor to traverse all object members similar to "this reference" in C++/PERL?
function Car(seat_sth, engine_sth, radio_sth) {
this.seats = seat_sth;
this.engine = engine_sth;
this.radio = radio_sth;
this.describe = describe_car();
}
function describe_car() {
for (var propname in this) {
document.write(propname + ": " + this[propname] + "<br>")
}
}
Just started JS, and not sure I am asking a right question. Thanks!