Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding some examples (comparison with node.js would have helped my a …

…lot few days ago)
  • Loading branch information...
commit 6dd4fbedd978308c905eafe1da6a6797d469ad78 1 parent df3cfae
Irakli Gozalishvili authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 resources/public/synonym.html
22 resources/public/synonym.html
View
@@ -59,13 +59,18 @@ <h1 id="title">Himera <div>Translations from JavaScript</div></h1>
<h4>Define a library</h4>
<div class="cheat-box-container eight columns">
<div class="cheat-box">
- <pre class="brush: js">// No native implementation</pre>
+ <pre class="brush: js">// No native implementation in JS
+// In node.js you write modules
+// To expose you need to put into exports
+exports.foo = function(bar) { return doSomethingWith(bar) }</pre>
</div>
</div>
<div class="cheat-box-container eight columns">
<div class="cheat-box">
- <pre class="brush: clojure">(ns my.library)</pre>
+ <pre class="brush: clojure">(ns my.library)
+;; To expose you need to add :export metadata
+(defn ^:export foo [bar] (do-something-with bar)</pre>
</div>
</div>
</div>
@@ -74,7 +79,9 @@ <h1 id="title">Himera <div>Translations from JavaScript</div></h1>
<h4>Use a library</h4>
<div class="cheat-box-container eight columns">
<div class="cheat-box">
- <pre class="brush: js">// No native implementation</pre>
+ <pre class="brush: js">// No native implementation
+// In node.js you require modules
+var other = require('other/library')</pre>
</div>
</div>
@@ -663,6 +670,7 @@ <h3 class="syn-clear">Booleans</h4>
<pre class="brush: js">
// == operator is coercive
1 == "1" // => true
+1 === "1" // => false
// sometimes based on value
{} == {} // => false</pre>
@@ -1180,8 +1188,12 @@ <h3 class="syn-clear">Booleans</h4>
return "Woof!";
}
-// lacking indirection no way to provide defaults
-(1).sound() // Error
+// You can provide defaults but it's risky as
+// you share same namespace and may have conflicts.
+Object.prototype.sound = function() {
+ return "... silence ..."
+}
+(1).sound() // "... silence ..."
</pre>
</div>
</div>

1 comment on commit 6dd4fbe

David Nolen

If we're going to talk about Node.js we should make a new subsection. The last bit is not equivalent to extending to default in ClojureScript since these work for nil. You cannot add methods to null in JavaScript.

Please sign in to comment.
Something went wrong with that request. Please try again.