Javascript constructor "this reference"


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Javascript constructor "this reference"

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):
Code:
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?
Code:
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!

Last edited by yifangt; 07-19-2017 at 06:24 PM..
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Excellent Oracle JET Video - "Finally, JavaScript Is Easy!"
Neo
This is a video well worth watching if you have any interests at all in the future of web development, web development frameworks and Javascript. https://www.youtube.com/watch?v=V8mhIEeTMCc . Fixed typo in Oracle Jet URL (oraclejet.org)... What is on Your Mind?
0
What is on Your Mind?
Why using this kind of format in Web Development <script type="text/javascript"><!-- ...//--></scrip
Anna Hussie
I am just wondering why do programmers are using this when programming the web? When you making a joomla templates and the more focus in your mind is to target the search engines then java is very important.Not to use that.... Web Development
2
Web Development
awk command to replace ";" with "|" and ""|" at diferent places in line of file
shis100
Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone...... Shell Programming and Scripting
7
Shell Programming and Scripting