2015-12-09 14 views
9

olarak yeniden ihraç ben ModuleA var:ES6 modülü: Bazı işlevleri verir nesne

:

// moduleA.js 
export function f1() {...} 
export function f2() {...} 

ModuleB içinde ModuleA tüm ihracat ihracat yeniden ve bir nesne gibi görünüyor yapmak için herhangi bir yolu var mı

// moduleB.js 
export * as a from 'moduleA'; // pseudo code, doesn't work 

ben bu şekilde kullanabilirsiniz diye mi?

// main.js 
import {a} from 'moduleB'; 
a.f1(); 
a.f2(); 

cevap

16

Sözdizimi henüz desteklenmiyor ancak a proposal for it var.

Sadece Babel.js ile şimdi kullanabilir veya yapın:

import * as a from '...'; 
export {a}; 
+1

- teklif O 'babel-önceden ayarlanmış-env' veya' babel-önceden ayarlanmış-latest' bulunmayanlar aşamasında 1. hala serbest. http://babeljs.io/docs/plugins/transform-export-extensions/ file1' 'yapısını ve' file2' –

-1

file1.js

export let uselessObject = { 
    con1 : function() { 
    console.log('from file1.js') 
    } 
} 

file2.js

import { uselessObject } from './file1.js' 

uselessObject.con2 = function(){ 
    console.log('from file2.js ') 
} 

export { uselessObject } from './file1.js' 

Index js

import { uselessObject } from './file2.js' 
uselessObject.con1() 
uselessObject.con2() 

Çıktı kimse seyir için

from file1.js 
from file2.js 
+0

.. amacını çözme: Sen ayrı olarak yüklemeniz gerekecektir .. daha ne istiyorsun – Bergi

+0

çalışma koduna değişen gerektirecektir – vijay

+0

Çalışma kodu, iyi kod – Bergi

İlgili konular