cmpenn
9 months agoContributor
Calling JavaScript Classes from other files
Hi all,
I was trying to update some of our old JScript files and was hoping to use JavaScript classes for at
least a few cases...unfortunately, I can't seem to do so.
I cannot seem to get the class to be called from another file, and looking at TestComplete documentation, the only way to do that was deprecated a while ago.
Does anyone have any examples of how to do this, or am I right in that it cannot be done?
I've tried using require and using const, but no luck. Below is a sanitized version of what I wrote.
The Class:
<SPAN class="token keyword">class</SPAN> <SPAN class="token class-name">MainClass</SPAN> <SPAN class="token punctuation">{</SPAN>
<SPAN class="token function">constructor</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN> <SPAN class="token punctuation">{</SPAN>
<SPAN class="token punctuation">}</SPAN>
<SPAN class="token function">Start</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN> <SPAN class="token punctuation">{</SPAN>
<SPAN class="token function">Close</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN> <SPAN class="token punctuation">{</SPAN>
<SPAN class="token punctuation">}</SPAN>
<SPAN class="token punctuation">}</SPAN>
module<SPAN class="token punctuation">.</SPAN>exports <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">{</SPAN><SPAN class="token literal-property property">MainApp</SPAN><SPAN class="token operator">:</SPAN> MainClass<SPAN class="token punctuation">}</SPAN>
The file I'm calling it from:
<SPAN class="token keyword">var</SPAN> main <SPAN class="token operator">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token string">"Main"</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token keyword">const</SPAN> mainApp <SPAN class="token operator">=</SPAN> <SPAN class="token keyword">new</SPAN> <SPAN class="token class-name">main<SPAN class="token punctuation">.</SPAN>MainApp</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
mainApp<SPAN class="token punctuation">.</SPAN><SPAN class="token function">Start</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
Here's an example,