Appeal to the constants being inside of this constant?


1. Previously, to get access to the constants used PATHS.src (example below). Right to do so?

const PATHS = {
 src: 'src'

2. It took to the element constant, while this constant (example below), applied in a similar way PATHS.src - ReferenceError: PATHS is not defined . So how to access an element in this case?

const PATHS = {
 src: 'src',
 srcAssets: PATHS.src + '/assets',

3. How to call these "elements" in the constant. Methods, properties, elements...?

Thank you!
March 12th 20 at 08:04
3 answers
March 12th 20 at 08:06
var PATHS = {
 src: 'src',
 get srcAssets() {
 return this.src + '/assets';
March 12th 20 at 08:08
I don't think that was possible. By priority, first is formed the object, then its reference is passed in PATHS. Can do using functional class
const PATHS = new function () {
 this.src = 'src';
 this.srcAssets = this.src + '/assets';

If you don't want to write this, that you can so
const PATHS = (function () {
 const basePath = 'src';
 return {
 src: basePath,
 srcAssets: basePath + '/assets',
March 12th 20 at 08:10
Creates an object without a name. The object has a property src , and then you add a property srcAssets.

In the form const X = {...} first right side object is created without a name with the specified properties, then the reference to the object to be stored as a constant X. Therefore, the right part before to use X – he has not yet been determined.

Good options already offered in the responses. You can still create a X with known and independent properties, and later to ask him more properties:
const PATHS = {
 src: 'src'
PATHS.srcAssets = PATHS.src + '/assets';

This does not contradict the "constancy".

Find more questions by tags JavaScript