Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Property with three dots (...)

I have a problem with code I am supposed to work with. I found a syntax I am not familiar with and I have trouble googling the documentation:

export const Something = class Something {
    constructor(someObject = {}) {
        this.someObject = {...Something.someObjectDefaultAsStaticMethod,...someThing};
    };
// The rest of the class
};

I have problems understanding what the three dots (...) in front of the parameter do. And "dots in parameter javascript" is a bad search term. Can someone help me, maybe tell me what this syntax is actually called or just directly link me to documentation?

like image 645
SomeStranger314 Avatar asked Jan 26 '18 15:01

SomeStranger314


People also ask

What do 3 dots mean in Typescript?

The three dots are known as the spread operator from Typescript (also from ES7). The spread operator return all elements of an array.

What is triple period in JavaScript?

three dots in javascript. The spread syntax is a new addition to the set of operators in JavaScript ES6. It takes in an iterable (e.g an array) and expands it into individual elements. The spread syntax is commonly used to make shallow copies of JS objects.

What is '$' in JavaScript?

Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

What is the significance of the three dots in this function signature?

operator in it, and it basically means " ... and everything else should go into $strings ". You can pass 2 or more arguments into this function and the second and subsequent ones will be added to the $strings array , ready to be used. Follow this answer to receive notifications.


1 Answers

That is not ES6 but has only been added in ECMAScript 2018.

It is called "Object Rest/Spread Properties" and is part of the Spread Syntax.

like image 102
str Avatar answered Oct 04 '22 05:10

str