diff options
Diffstat (limited to 'src/qml/doc/src/javascript/imports.qdoc')
-rw-r--r-- | src/qml/doc/src/javascript/imports.qdoc | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/src/qml/doc/src/javascript/imports.qdoc b/src/qml/doc/src/javascript/imports.qdoc index 9227f0e604..ef5376cb54 100644 --- a/src/qml/doc/src/javascript/imports.qdoc +++ b/src/qml/doc/src/javascript/imports.qdoc @@ -1,29 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \page qtqml-javascript-imports.html \title Importing JavaScript Resources in QML @@ -64,7 +40,7 @@ objects such as \c Date and \c Math). The functions defined in an imported JavaScript file are available to objects defined in the importing QML document, via the \c{"Qualifier.functionName(params)"} syntax. Functions in JavaScript resources -may take parameters whose type can be any of the supported QML basic types or +may take parameters whose types can be any QML value types or object types, as well as normal JavaScript types. The normal \l{qtqml-cppintegration-data.html}{data type conversion rules} will apply to parameters and return values when calling such functions from QML. @@ -95,17 +71,18 @@ or modules). A JavaScript resource may import another in the following fashion: \code -.import "filename.js" as Qualifier +import * as MathFunctions from "factorial.mjs"; \endcode -For example: +Or: \code -import * as MathFunctions from "factorial.mjs"; +.import "filename.js" as Qualifier \endcode -The latter is standard ECMAScript syntax for importing ECMAScript modules, and +The former is standard ECMAScript syntax for importing ECMAScript modules, and only works from within ECMAScript modules as denoted by the \c mjs file -extension. The former is an extension to JavaScript provided by the \c QML -engine and will work also with non-modules. +extension. The latter is an extension to JavaScript provided by the \c QML +engine and will work also with non-modules. As an extension superseded by the +ECMAScript standard, its usage is discouraged. When a JavaScript file is imported this way, it is imported with a qualifier. The functions in that file are then accessible from the importing script via the @@ -156,5 +133,13 @@ var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3 In particular, this may be useful in order to access functionality provided via a singleton type; see QML_SINGLETON for more information. -\note The .import syntax doesn't work for scripts used in the \l {WorkerScript} +Your JavaScript resource by default can access all imports of the component +that imports the resource. It does not have access to the componpents's imports +if it is declared as a stateless library (using \c{.pragma library}) or contains +an explicit \c{.import} statment. + +\note The .import syntax doesn't work for scripts used in \l {WorkerScript} + +\sa {Defining JavaScript Resources in QML} + */ |