mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Adding an existential infix operator example.
This commit is contained in:
parent
9f56c92497
commit
2ac5ee4062
4 changed files with 101 additions and 94 deletions
|
@ -1,6 +1,8 @@
|
||||||
solipsism = true if mind? and not world?
|
solipsism = true if mind? and not world?
|
||||||
|
|
||||||
speed ?= 140
|
speed ?= 75
|
||||||
|
|
||||||
|
footprints = yeti ? "bear"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -608,7 +608,7 @@ coffee --bare --print --stdio</pre>
|
||||||
It can also be used for safer conditional assignment than <tt>||=</tt>
|
It can also be used for safer conditional assignment than <tt>||=</tt>
|
||||||
provides, for cases where you may be handling numbers or strings.
|
provides, for cases where you may be handling numbers or strings.
|
||||||
</p>
|
</p>
|
||||||
<%= code_for('existence', 'speed') %>
|
<%= code_for('existence', 'footprints') %>
|
||||||
<p>
|
<p>
|
||||||
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
||||||
up null references in a chain of properties. Use it instead
|
up null references in a chain of properties. Use it instead
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
var solipsism;
|
var footprints, solipsism;
|
||||||
if ((typeof mind != "undefined" && mind !== null) && !(typeof world != "undefined" && world !== null)) {
|
if ((typeof mind != "undefined" && mind !== null) && !(typeof world != "undefined" && world !== null)) {
|
||||||
solipsism = true;
|
solipsism = true;
|
||||||
}
|
}
|
||||||
typeof speed != "undefined" && speed !== null ? speed : speed = 140;
|
typeof speed != "undefined" && speed !== null ? speed : speed = 75;
|
||||||
|
footprints = typeof yeti != "undefined" && yeti !== null ? yeti : "bear";
|
16
index.html
16
index.html
|
@ -1111,22 +1111,26 @@ globals = (function() {
|
||||||
</p>
|
</p>
|
||||||
<div class='code'><pre class="idle">solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> mind<span class="Keyword">?</span> <span class="Keyword">and</span> <span class="Keyword">not</span> world<span class="Keyword">?</span>
|
<div class='code'><pre class="idle">solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> mind<span class="Keyword">?</span> <span class="Keyword">and</span> <span class="Keyword">not</span> world<span class="Keyword">?</span>
|
||||||
|
|
||||||
speed <span class="Keyword">?</span><span class="Keyword">=</span> <span class="Number">140</span>
|
speed <span class="Keyword">?</span><span class="Keyword">=</span> <span class="Number">75</span>
|
||||||
|
|
||||||
|
footprints <span class="Keyword">=</span> yeti <span class="Keyword">?</span> <span class="String"><span class="String">"</span>bear<span class="String">"</span></span>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</pre><pre class="idle"><span class="Storage">var</span> solipsism;
|
</pre><pre class="idle"><span class="Storage">var</span> footprints, solipsism;
|
||||||
<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&</span><span class="Keyword">&</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
|
<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&</span><span class="Keyword">&</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
|
||||||
solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
|
solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
|
||||||
}
|
}
|
||||||
<span class="Keyword">typeof</span> speed <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span> ? speed : speed <span class="Keyword">=</span> <span class="Number">140</span>;
|
<span class="Keyword">typeof</span> speed <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span> ? speed : speed <span class="Keyword">=</span> <span class="Number">75</span>;
|
||||||
</pre><button onclick='javascript: var solipsism;
|
footprints <span class="Keyword">=</span> <span class="Keyword">typeof</span> yeti <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> yeti <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span> ? yeti : <span class="String"><span class="String">"</span>bear<span class="String">"</span></span>;
|
||||||
|
</pre><button onclick='javascript: var footprints, solipsism;
|
||||||
if ((typeof mind != "undefined" && mind !== null) && !(typeof world != "undefined" && world !== null)) {
|
if ((typeof mind != "undefined" && mind !== null) && !(typeof world != "undefined" && world !== null)) {
|
||||||
solipsism = true;
|
solipsism = true;
|
||||||
}
|
}
|
||||||
typeof speed != "undefined" && speed !== null ? speed : speed = 140;;alert(speed);'>run: speed</button><br class='clear' /></div>
|
typeof speed != "undefined" && speed !== null ? speed : speed = 75;
|
||||||
|
footprints = typeof yeti != "undefined" && yeti !== null ? yeti : "bear";;alert(footprints);'>run: footprints</button><br class='clear' /></div>
|
||||||
<p>
|
<p>
|
||||||
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
The accessor variant of the existential operator <tt>?.</tt> can be used to soak
|
||||||
up null references in a chain of properties. Use it instead
|
up null references in a chain of properties. Use it instead
|
||||||
|
@ -1910,7 +1914,7 @@ task(<span class="String"><span class="String">'</span>build:parser<span class="
|
||||||
asynchronous exceptions. Using <tt>--watch</tt> now prints timestamps as
|
asynchronous exceptions. Using <tt>--watch</tt> now prints timestamps as
|
||||||
files are compiled. Fixed some accidentally-leaking variables within
|
files are compiled. Fixed some accidentally-leaking variables within
|
||||||
plucked closure-loops. Constructors now maintain their declaration
|
plucked closure-loops. Constructors now maintain their declaration
|
||||||
location within a class body.
|
location within a class body. Dynamic object keys were removed.
|
||||||
Nested classes are now supported. Fixes execution context for naked
|
Nested classes are now supported. Fixes execution context for naked
|
||||||
splatted functions. Bugfix for inversion of chained comparisons.
|
splatted functions. Bugfix for inversion of chained comparisons.
|
||||||
Chained class instantiation now works properly with splats.
|
Chained class instantiation now works properly with splats.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue