Sponsored Content
Top Forums Web Development Javascript constructor "this reference" Post 303000786 by yifangt on Wednesday 19th of July 2017 06:15:43 PM
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 07:24 PM..
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

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... (7 Replies)
Discussion started by: shis100
7 Replies

2. Web Development

Why using this kind of format in Web Development <script type="text/javascript"><!-- ...//--></scrip

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. (2 Replies)
Discussion started by: Anna Hussie
2 Replies

3. Programming

make fails with "undefined reference to..."

i am compiling a program called vasp on suse and get the following error. there are many more preprocess and ifort commands prior so i just grabbed the tail of the log file: ./preprocess <main.F | /usr/bin/cpp -P -C -traditional >main.f90 -DMPI -DHOST=\"LinuxIFC\" -DIFC -Dkind8 -DNGZhalf... (6 Replies)
Discussion started by: crimso
6 Replies

4. Programming

Compiling C++ code with NetCDF libraries: "undefined reference"

Hi! I am trying to compile a C++ code with cmake and gcc on Ubuntu. The code uses NetCDF4 libraries. I specify the path to these libraries as follows: -I/usr/local/include -L/usr/local/lib -lnetcdf -lnetcdf_c++4 "ccmake" and "cmake" work fine. After typing "make" I receive the error... (0 Replies)
Discussion started by: Alauda
0 Replies

5. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

6. What is on Your Mind?

Excellent Oracle JET Video - "Finally, JavaScript Is Easy!"

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) (0 Replies)
Discussion started by: Neo
0 Replies

7. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
Mail::SPF::Base(3)					User Contributed Perl Documentation					Mail::SPF::Base(3)

NAME
Mail::SPF::Base - Base class for Mail::SPF classes SYNOPSIS
use base 'Mail::SPF::Base'; sub new { my ($class, @options) = @_; my $self = $class->SUPER::new(@options); ... return $self; } DESCRIPTION
Mail::SPF::Base is a common base class for all Mail::SPF classes. Constructor The following constructor is provided: new(%options): returns Mail::SPF::Base Creates a new object of the class on which the constructor was invoked. The provided options are stored as key/value pairs in the new object. The "new" constructor may also be called on an object, in which case the object is cloned. Any options provided override those from the old object. There are no common options defined in Mail::SPF::Base. Class methods The following class methods are provided: class: returns string Returns the class name of the class or object on which it is invoked. Class methods The following class methods are provided: make_accessor($name, $readonly): returns code-ref Creates an accessor method in the class on which it is invoked. The accessor has the given name and accesses the object field of the same name. If $readonly is true, the accessor is made read-only. Instance methods There are no common instance methods defined in Mail::SPF::Base. SEE ALSO
Mail::SPF For availability, support, and license information, see the README file included with Mail::SPF. AUTHORS
Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> perl v5.12.1 2010-07-05 Mail::SPF::Base(3)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy