Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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\page qmllint-warnings-and-errors-with.html
6\ingroup qmllint-warnings-and-errors
7
8\title With Statements
9\brief With statements are strongly discouraged in QML.
10
11\section1 With Statements
12
13\section2 What happened?
14The JavaScript \c{with} statement was used.
15
16\section2 Why is this bad?
17With statements might cause false positives when analysing unqualified identifiers. Also, \c{with}
18statements are
19\l{https://262.ecma-international.org/#sec-with-statement}{marked as deprecated by the latest JavaScript standard}.
20
21\section2 Example
22\qml
23import QtQuick
24
25Item {
26 function f() {
27 with (Math) {
28 return PI
29 }
30 }
31}
32\endqml
33You can fix this warning by replacing the \c{with} statement with a destructuring property,
34for example:
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*/
50