👤
Home Man
Search
Today's Posts
Register

Discuss Web Programming and Web Server Administration, including LAMP, Apache, MySQL, HTML, SEO, and other Web APIs and topics.

Javascript constructor "this reference"

Tags
constructor, javascript, object

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 07-19-2017
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 to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using "mailx" command to read "to" and "cc" email addreses from input file asjaiswal UNIX for Dummies Questions & Answers 2 10-11-2014 09:32 PM
Compiling C++ code with NetCDF libraries: "undefined reference" Alauda Programming 0 09-21-2012 01:26 PM
I got "undefined reference to" on gcc sluge Solaris 0 07-09-2012 04:57 AM
make fails with "undefined reference to..." crimso Programming 6 10-19-2011 10:03 AM
Why using this kind of format in web programming <script type="text/javascript"><!-- ...//--></scrip Anna Hussie Web Programming 2 05-23-2011 11:17 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM


All times are GMT -4. The time now is 05:11 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password