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\page qmllint-warnings-and-errors-with.html
6\ingroup qmllint-warnings-and-errors
7
8\title With
9\brief [with] With statements are strongly discouraged in QML.
10
11\qmllintwarningcategory with
12
13\section1 With statements
14
15\section2 What happened?
16The JavaScript \c{with} statement was used.
17
18\section2 Why is this bad?
19With statements might cause false positives when analysing unqualified identifiers. Also, \c{with}
20statements are
21\l{https://262.ecma-international.org/#sec-with-statement}{marked as deprecated by the latest JavaScript standard}.
22
23\section2 Example
24\qml
25import QtQuick
26
27Item {
28 function f() {
29 with (Math) {
30 return PI
31 }
32 }
33}
34\endqml
35To fix this warning, replace the \c{with} statement with a destructuring property:
36\qml
37import QtQuick
38
39Item {
40 function f() {
41 const { PI } = Math;
42 return PI
43 }
44}
45
46\endqml
47
48\note You can find more replacement ideas
49\l{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with?retiredLocale=de#examples}{here}.
50*/