Click here to Skip to main content
15,499,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good evening guys, how are you? I am trying to understand the concept behind parentheses ('Tesla', 'Black', 20000); that involve the parameters at the end of the function. If I remove it the Car variable becomes a function otherwise it is an object. Is this parenthesis a self-invoking function?



JavaScript
let Car = function (model, color, price) {
    this.model = model; 
    this.color = color;
    this.price = price;
 
     this.changeColor = function(){
        
        this.color = 'Blue';
    }
    
    this.getCar = function() {
        this.changeColor();  
      return console.log(`Model: ${this.model} Color: ${this.color} Price: ${this.price}` ) ;
    }  
    
 return this;
    
}('Tesla', 'Preto', 20000);


What I have tried:

......................................................................................................................
Posted
Updated 22-Dec-19 23:09pm

1 solution

See JavaScript Classes[^].

The sample above combines the constructor with the variable assignment so after execution, the variable named Car will have the following properties:
model : 'Tesla'
color : 'Preto'
price : 20,000
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900