Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
with.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\ingroup qmllint-warnings-and-errors
6
7\title With
8\brief [with] With statements are strongly discouraged in QML.
9
10\qmllintwarningcategory with
11
12\section1 With statements
13
14\section2 What happened?
15The JavaScript \c{with} statement was used.
16
17\section2 Why is this bad?
18With statements might cause false positives when analysing unqualified identifiers. Also, \c{with}
19statements are
20\l{https://262.ecma-international.org/#sec-with-statement}{marked as deprecated by the latest JavaScript standard}.
21
22\section2 Example
23\qml
24import QtQuick
25
26Item {
27 function f() {
28 with (Math) {
29 return PI
30 }
31 }
32}
33\endqml
34To fix this warning, replace the \c{with} statement with a destructuring property:
35\qml
36import QtQuick
37
38Item {
39 function f() {
40 const { PI } = Math;
41 return PI
42 }
43}
44
45\endqml
46
47\note You can find more replacement ideas
48\l{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with?retiredLocale=de#examples}{here}.
49*/