Skip to content

Commit d0dd952

Browse files
Reorder section for jsiter alphabetically
1 parent 2a79461 commit d0dd952

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

transcrypt/docs/sphinx/special_facilities.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ An example of its use is to encapsulate a JavaScript library as a Python module,
228228

229229
Note that since {} is used as placeholder in Python formatting, any normal { and } in your JavaScript in the code parameter have to be doubled. If you just want to include a literal piece of JavaScript without any replacements, you can avoid this doubling by using __pragma__ ('js', '{}', <my_piece_of_JS_code>).
230230

231+
Create bare JavaScript objects and iterate over their attributes from Python: __pragma__ ('jsiter') and __pragma__ ('nojsiter')
232+
-------------------------------------------------------------------------------------------------------------------------------
233+
Normally a Python *{...}* literal is compiled to *dict ({...})* to include the special attributes and methods of a Python dict, including e.g. an iterator. When *__pragma__ ('jsiter')* is active, a *Python {...}* literal is compiled to a bare *{...}*, without special attributes or methods. To still be able to iterate over the attributes of such a bare JavaScript object from Python, when *__pragma__ ('jsiter')* is active, a Python *for ... in ...* is literally translated to a JavaScript *for (var ... in ...)*. The main use case for this pragma is conveniently looping through class attributes in the *__new__* method of a metaclass. As a more flexible, but less convenient alternative, *__pragma__ ('js', '{}', '''...''')* can be used.
234+
235+
An example of the use of this pragma is the following:
236+
237+
.. literalinclude:: ../../development/automated_tests/transcrypt/metaclasses/__init__.py
238+
:start-after: from org.transcrypt.stubs.browser import __pragma__
239+
:end-before: class Uppercaser (metaclass = UppercaserMeta):
240+
:tab-width: 4
241+
:caption: Use of __pragma__ ('jsiter') and __pragma ('nojsiter') to manipulate class attributes in a metaclass
242+
231243
__pragma__ ('jskeys') and __pragma__ ('nojskeys')
232244
-------------------------------------------------
233245
Normally in Python, dictionary keys without quotes are interpreted as identifiers and dictionary keys with quotes as string literals. This is more flexible than the JavaScript approach, where dictionary keys with or without quotes are always interpreted as string literals. However to better match the documentation and habits with some JavaScript libraries, such as plotly.js, dictionary keys without quotes can be optionally interpreted as string literals. While the -jk command line switch achieves this globally, the preferred way is to switch on and off this facility locally.
@@ -299,15 +311,3 @@ Example:
299311
.. literalinclude:: ../../development/manual_tests/xtrans/test_for_docs.js
300312
:tab-width: 4
301313
:caption: The resulting translated file test.js
302-
303-
Create bare JavaScript objects and iterate over their attributes from Python: __pragma__ ('jsiter') and __pragma__ ('nojsiter')
304-
-------------------------------------------------------------------------------------------------------------------------------
305-
Normally a Python *{...}* literal is compiled to *dict ({...})* to include the special attributes and methods of a Python dict, including e.g. an iterator. When *__pragma__ ('jsiter')* is active, a *Python {...}* literal is compiled to a bare *{...}*, without special attributes or methods. To still be able to iterate over the attributes of such a bare JavaScript object from Python, when *__pragma__ ('jsiter')* is active, a Python *for ... in ...* is literally translated to a JavaScript *for (var ... in ...)*. The main use case for this pragma is conveniently looping through class attributes in the *__new__* method of a metaclass. As a more flexible, but less convenient alternative, *__pragma__ ('js', '{}', '''...''')* can be used.
306-
307-
An example of the use of this pragma is the following:
308-
309-
.. literalinclude:: ../../development/automated_tests/transcrypt/metaclasses/__init__.py
310-
:start-after: from org.transcrypt.stubs.browser import __pragma__
311-
:end-before: class Uppercaser (metaclass = UppercaserMeta):
312-
:tab-width: 4
313-
:caption: Use of __pragma__ ('jsiter') and __pragma ('nojsiter') to manipulate class attributes in a metaclass

0 commit comments

Comments
 (0)