Does ECMAScript-6 import a nested function?

Hi, I switched to javascript ECMAScript-6 syntax some time ago and I like it! One thing that I noticed and cannot find the final answer is the use of nested destructive syntax when importing. I mean something like this ..

Suppose I have a file that looks like this.

export const SomeUtils = _.bindAll({ //lodash _
    someFunc1(params){
        // .... stuff here
    },
    someFunc2(params){
        // .... stuff here
    },
    someFunc3(params){
        // .... stuff here
    }
});
// ... many more of these

I did something like this to get a specific function

import {Utils} from '../some/path/to/utils';
var {someFunc2} = Utils;

To understand, is there a way to do one row import for someFunc2? how can you do the destruction assignment of nested objects with parentheses? (Aka:) {Utils: [{someFunc2}]}?

I used var someFunc2 = require('../some/path/to/utils').someFunc2;, but I can’t figure out how to do this using the import statement

+4
2

, ES6 . , , - ( ). , require(…).someFunc2.


, .

export function someFunc1(params){
    // .... stuff here
}
export function someFunc2(params){
    // .... stuff here
}
export function someFunc3(params){
    // .... stuff here
}

import {someFunc2} from '../some/path/to/utils';
+5

, , :

const Utils = _.bindAll({ //lodash _
    someFunc1(params){
        // .... stuff here
    },
    someFunc2(params){
        // .... stuff here
    },
    someFunc3(params){
        // .... stuff here
    }
});

export default Utils;

, ...

import Utils, { someFunc2 } from '../some/path/to/utils';
-2

Source: https://habr.com/ru/post/1619660/


All Articles