5

In order to include one .js file in another .js file I tried writing the following in a .js file.

var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'helper.js';
head.appendChild(script);

I got the error: ReferenceError: document is not defined

Then I wrote:

<script type="text/javascript" charset="utf-8">
   $(documuent).ready(function () { var editChange = $('td').replaceWith('<td id = "@Html.ValueFor(x => x.name)" >'); });
</script>

on the top of it, but got the error: SyntaxError: Unexpected token <

Problem is that here no browser is involved. This .js file is working along QML and getting compiled with qmake.

What is the syntax for this?

1 Answer 1

8

Here is the documentation on "Importing JavaScript Resources in QML" with the specific case of importing in another JS file

If you have a file helper.js and you want to use its functions in another javascript file you can do like that:

.import "helper.js" as Helper

Then you can use one of its functions like this:

Helper.myFunction();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.