Added a note on "sub" return values

gh-pages
Hauke D 7 years ago
parent 35f18e092c
commit aa86663451

@ -529,7 +529,7 @@ The exceptions are Perl `sub`s and `WebPerl::JSObject`s.
- Perl arrayrefs become JavaScript arrays (deep copy)
- Perl hashrefs become JavaScript objects (deep copy)
- Perl coderefs become JavaScript functions -
- Perl coderefs become JavaScript functions² -
**Warning:** please see the discussion in
["Memory Management and Anonymous `sub`s"](#memory-management-and-anonymous-subs)!
- Perl `WebPerl::JSObject`s become references to the wrapped JavaScript objects
@ -550,6 +550,13 @@ future be extended to return more than that, similar to `WebPerl::js()`,
and then the passing of Perl values to JavaScript could be accomplished
differently as well.
² **Remember** that Perl `sub`s without an explicit `return` statement will
implicitly return the value of the last statement (if it is an expression).
This value will in turn be passed to JavaScript, which may be inefficient
if this value is not needed, and it may cause errors if the return value cannot
be encoded to JavaScript. Therefore it is recommended to get into the
habit of adding an explicit `return;` at the end of `sub`s passed to JS.
### `js_new()`
This function is a convenience function for calling JavaScript's `new`.

Loading…
Cancel
Save