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?
15
The JavaScript \c{with} statement was used.
16
17
\section2 Why is this bad?
18
With statements might cause false positives when analysing unqualified identifiers. Also, \c{with}
19
statements 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
24
import QtQuick
25
26
Item {
27
function f() {
28
with (Math) {
29
return PI
30
}
31
}
32
}
33
\endqml
34
To fix this warning, replace the \c{with} statement with a destructuring property:
35
\qml
36
import QtQuick
37
38
Item {
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
*/
qtdeclarative
src
qml
doc
src
qmllint
with.qdoc
Generated on
for Qt by
1.16.1