Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other/self changing examples, MarkTagAsUsed pragma #237

Merged
merged 10 commits into from
Jan 21, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs(feature): Documented examples for when self and other change
gurpreetsinghmatharoo committed Jan 15, 2025

Verified

This commit was signed with the committer’s verified signature.
jorisv Joris Vaillant
commit dfa28a29c86f1de68dc8274a62854cd92d45c960
Original file line number Diff line number Diff line change
@@ -45,8 +45,47 @@ <h2 id="h">When &#39;other&#39; changes</h2>
<p>This section will describe those cases in relation to how <span class="inline2">other</span> changes:</p>
<ul class="colour">
<li>Inside a <span class="inline3_func"><a data-xref="{title}" href="../Language_Features/with.htm">with</a></span> block, <span class="inline2">other</span> will be the instance or struct that called the <span class="inline2">with()</span> function</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = {<br />
    value : 99<br />
}<br />
<br />
with (_struct) <br />
{<br />
    show_debug_message(other.value); // Prints 40<br />
}
</p>
<ul class="colour">
<li>When calling a <a href="../Method_Variables.htm">method</a> that is bound to an instance or a struct, <span class="inline2">other</span> will be the instance or struct that called that method</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = {<br />
    value : 99,<br />
    func : function () {<br />
        return other.value;<br />
    }<br />
}<br />
<br />
show_debug_message(_struct.func()); // Prints 40
</p>
<ul class="colour">
<li>When calling an unbound constructor function, <span class="inline2">other</span> will be the instance or struct that called that function. If the constructor is bound as a method, then <span class="inline2">other</span> will be the instance or struct to which the constructor method is bound.</li>
</ul>
<p class="code">value = 40;<br />
<br />
item = function () constructor {<br />
    value = 99;<br />
    <br />
    copied_value = other.value;<br />
}<br />
<br />
my_item = new item();<br />
show_debug_message(my_item.copied_value); // Prints 40
</p>
<ul class="colour">
<li>When stored as a reference through a struct literal, covered below under &quot;<strong>&#39;other&#39; as a reference</strong>&quot;.</li>
</ul>
<h3 id="legacy_other_behaviour">Legacy other Behaviour</h3>
Original file line number Diff line number Diff line change
@@ -29,7 +29,33 @@ <h2 id="h">When &#39;self&#39; changes</h2>
<ul class="colour">
<li>Inside a <span class="inline3_func"><a data-xref="{title}" href="../Language_Features/with.htm">with</a></span> block, as shown above</li>
<li>When calling a <a href="../Method_Variables.htm">method</a> that is bound to an instance or a struct, the <span class="inline2">self</span> during the execution of that function will be the instance or struct to which the method is bound</li>
</ul>
<p class="code">value = 40;<br />
<br />
var _struct = {<br />
    value : 99,<br />
    func : function () {<br />
        return self.value;<br />
    }<br />
}<br />
<br />
show_debug_message(_struct.func()); // Prints 99
</p>
<ul class="colour">
<li>When calling a constructor function, <span class="inline2">self</span> will refer to the new struct that is being generated as a result of that function.</li>
</ul>
<p class="code">value = 40;<br />
<br />
item = function () constructor {<br />
    value = 99;<br />
    <br />
    copied_value = self.value;<br />
}<br />
<br />
my_item = new item();<br />
show_debug_message(my_item.copied_value); // Prints 99
</p>
<ul class="colour">
<li>When stored as a reference through a struct literal, covered below under &quot;<strong>&#39;self&#39; as a reference</strong>&quot;.</li>
</ul>
<p>In all of these cases, when <span class="inline2">self</span> changes to a new scope, <span class="inline2"><a href="other.htm">other</a></span> will be set to be the previous scope. The only exception is when a bound constructor method is called. This is described more in <a data-xref="{text}" href="other.htm#h">When &#39;other&#39; changes</a>.</p>