diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala index 68379985d..ae2408b46 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -97,7 +97,11 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.inc out.puts("this._io = _io;") out.puts("this._parent = _parent;") - out.puts("this._root = _root || this;") + if (name == rootClassName) { + out.puts("this._root = _root || this;") + } else { + out.puts("this._root = _root;") + } if (isHybrid) out.puts("this._is_le = _is_le;")