diff --git a/transcrypt/docs/sphinx/special_facilities.rst b/transcrypt/docs/sphinx/special_facilities.rst index 3c2f69862..53b83f104 100644 --- a/transcrypt/docs/sphinx/special_facilities.rst +++ b/transcrypt/docs/sphinx/special_facilities.rst @@ -61,11 +61,11 @@ To test the non-GUI part of your code in a desktop rather than a browser environ Creating JavaScript objects with __new__ () ------------------------------------------------------------- -While creating objects in Transcrypt mostly happens in the plain Python way, e.g. *canvas = Canvas ()*, objects from 3rd party JavaScript libraries often have to be created using *new*. In Transcrypt such objects are created by calling the *__new__* function, e.g. *canvas = __new__ (Canvas ()*, as can be seen in the :ref:`Pong example`. This mechanism is simple, follows Python's syntax rules and doesn't require updating of an encapsulation layer if a later version of the underlying JavaScript library features additional constructor functions. Therefore in most cases it is the preferred way to create objects who's initialization requires calling 3rd party JavaScript constructor functions. +While creating objects in Transcrypt mostly happens in the plain Python way, e.g. *canvas = Canvas ()*, objects from 3rd party JavaScript libraries often have to be created using *new*. In Transcrypt such objects are created by calling the *__new__* function, e.g. *canvas = __new__ (Canvas ())*, as can be seen in the :ref:`Pong example`. This mechanism is simple, follows Python's syntax rules and doesn't require updating of an encapsulation layer if a later version of the underlying JavaScript library features additional constructor functions. Therefore in most cases it is the preferred way to create objects who's initialization requires calling 3rd party JavaScript constructor functions. As an alternative, instantiation and construction can be encapsulated in one function call. Since this in fact creates an alternative API facade for the 3rd party JavaScript library, such an encapsulation should be kept separate from the original library, e.g. by putting it in a separate importable module. The JavaScript code for this encapsulation would e.g. be *.Canvas = function () {return new Canvas ();};*. After importing the facade module, canvas creation is straightforward: *canvas = Canvas ()*. -As a third alternative, encapsulation can be done in Python rather than JavaScript: *def Canvas (): return __new__ (<3rd party module name>.Canvas ()*. Also in this case the creation syntax is simple: *canvas = Canvas ()*. +As a third alternative, encapsulation can be done in Python rather than JavaScript: *def Canvas (): return __new__ (<3rd party module name>.Canvas ())*. Also in this case the creation syntax is simple: *canvas = Canvas ()*. The __pragma__ mechanism ------------------------