Closed devmondo closed 7 years ago
Hi @devmondo I think it can't be solved in javascript (es6) because of runtime B class still is undefined for A and C for B. javascript runtime interpreter can't recognize it.
oh ! thank you very much :) well the above is just fast code, the real code is that i put each one of them in file and import them.
so A and B work, the problem is C, i think it is cyclic issue or i may be wrong
Yes you are right it is cyclic references problem and also this problem exist on typescript. There are custom solutions for them one of them is https://github.com/casser/typescript-cyclic-references-problem
aha! i see, so this has to be implemented in your lib to make it work?
No. Just you can use this logic on your code // cached.js export function Cached(target,key,desc){ var initializer = desc.get; desc.get = function(){ return Object.defineProperty(this,key,{ value:initializer() })[key]; }; return desc; } // one.js import {Cached} from "./cached"; import {Two} from "./two"; export class One { @Cached static get two():Two{ return new Two() } } // two.js import {Cached} from "./cached"; import {One} from "./one"; export class Two { @Cached static get one():One{ return new One(); } } //main.js import {One} from "./one" import {Two} from "./two" console.info(One.two) console.info(Two.one)
Otherwise I think cyclic reference problem should solve in babel compiler.
@mench thank you man :) hope it is fixed somehow with babel
Thank you too :)
hi, the below is causing the error