diff options
Diffstat (limited to 'doc/src/declarative/javascriptblocks.qdoc')
-rw-r--r-- | doc/src/declarative/javascriptblocks.qdoc | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc index d221205..65877f9 100644 --- a/doc/src/declarative/javascriptblocks.qdoc +++ b/doc/src/declarative/javascriptblocks.qdoc @@ -200,37 +200,12 @@ Likewise, the \l {Component::onDestruction} attached property is triggered on component destruction. -\section1 Property Assignment vs Property Binding +\section1 JavaScript and Property Binding -When working with both QML and JavaScript, it is important to differentiate between -QML \l {Property Binding} and JavaScript value assignment. In QML, a property -binding is created using the \e {property: value} syntax: +Property bindings can be created in JavaScript by assigning the property with a \c function +that returns the required value. -\code -Rectangle { - width: otherItem.width -} -\endcode - -The \c width of the above \l Rectangle is updated whenever \c otherItem.width changes. On the other -hand, take the following JavaScript code snippet, that runs when the \l Rectangle is created: - -\code -Rectangle { - - Component.onCompleted: { - width = otherItem.width; - } -} -\endcode - -The \c width of this \l Rectangle is \e assigned the value of \c otherItem.width using the -\e {property = value} syntax in JavaScript. Unlike the QML \e {property: value} syntax, this -does not invoke QML property binding; the \c rectangle.width property is set to the value -of \c otherItem.width at the time of the assignment and will not be updated if that value -changes. - -See \l {Property Binding} for more information. +See \l {Binding Properties from JavaScript} for details. \section1 Receiving QML Signals in JavaScript @@ -315,10 +290,13 @@ This restriction exists as the QML environment is not yet fully established. To run code after the environment setup has completed, refer to \l {Running JavaScript at Startup}. -\o The value of \c this is currently undefined in QML +\o The value of \c this is currently undefined in QML in the majority of contexts + +The \c this keyword is supported when \l {Binding Properties from JavaScript} +{binding properties from JavaScript}. In all other situations, the value of +\c this is undefined in QML. -The value of \c this is undefined in QML. To refer to any element, provide -an \c id. For example: +To refer to any element, provide an \c id. For example: \qml Item { |