Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to export an object literal with ES6/2015?

Seemingly a very simple task...

export default function() {     return {         googleClientID:'xxxx'     } } 

Is it the best way to export object literal with app settings?

like image 527
Svitlana Avatar asked Jan 05 '16 19:01

Svitlana


People also ask

What is export default in ES6?

Export Default is used to export only one value from a file which can be a class, function, or object. The default export can be imported with any name.

Can you export default an object?

You can export object itself: export default { googleClientID:'xxxx' }; The difference is that in your case you will get brand new object every time you call exported function. In this case you will get the same object every time.

Can you export an object JavaScript?

The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the import declaration or dynamic import.


1 Answers

You can export object itself:

export default {     googleClientID:'xxxx' }; 

The difference is that in your case you will get brand new object every time you call exported function. In this case you will get the same object every time. Depends on what you need.

like image 110
madox2 Avatar answered Oct 14 '22 00:10

madox2