Scope/Function names and labels: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 1,029: | Line 1,029: | ||
The shell does not support the use of arbitrary line labels. |
The shell does not support the use of arbitrary line labels. |
||
=={{header|Wren}}== |
|||
Firstly, Wren doesn't support labels at all. |
|||
Secondly, functions (as opposed to methods) are first-class objects and have the same visibility as any other object. In other words, when defined in a particular scope, they are visible from the point of declaration to the end of that scope. |
|||
On the other hand, methods are always public members of a class and are visible throughout that class. Although technically a top-level class is visible throughout the module in which its defined, it is null prior to its definition. |
|||
The following example illustrates these points. |
|||
<lang ecmascript>//func.call() /* invalid, can't call func before its declared */ |
|||
var func = Fn.new { System.print("func has been called.") } |
|||
func.call() // fine |
|||
//C.init() /* not OK, as C is null at this point */ |
|||
class C { |
|||
static init() { method() } // fine even though 'method' not yet declared |
|||
static method() { System.print("method has been called.") } |
|||
} |
|||
C.init() // fine</lang> |
|||
{{out}} |
|||
<pre> |
|||
(as it stands) |
|||
func has been called. |
|||
method has been called. |
|||
(with line 1 uncommented) |
|||
[./scope_function_names line 3] Error at '}': Variable 'func' referenced before this definition (first use at line 1). |
|||
(with only line 7 uncommented) |
|||
func has been called. |
|||
Null does not implement 'init()'. |
|||
[./scope_function_names line 7] in (script) |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |