Room 208

Elaborate Burn

Posts from #javascript

The internet is for functions that invisibly mess with HTML comments

In other news, I’ve discovered that the Tumblr dashboard defines a JavaScript function called Tumblr.porn(). It is, as you might expect, useless – not quite a no-op, but almost essentially so.

// TW: gratuitous anonymous function abuse {{{
while (iterationsLeft) (function () {
    // ...
    for (i = 0; i < x; i++) (function () {
        // ...
        if (delta === i) (function () {
            // ...
        }()); else (function () {
            // ...
        }());
        // ...
    }());
    // ...
}());
// }}}

gif.js

A GIF encoder implemented in JavaScript, for when you want to… uh, in-browser… I actually can’t think of a use case for this. Maybe if you have a pathological aversion to setTimeout? It is kinda cool, though.

It’s patch time!

diff --git a/dichotomy.html b/dichotomy.html
index 608a614..4ea860e 100644
--- a/dichotomy.html
+++ b/dichotomy.html
@@ -445,5 +445,19 @@ nav li {
 <li><a href="{RSS}">RSS</a></li>
 </ul>
 </nav>
+
+<script>
+(function () {
+    var as = document.getElementsByTagName('a');
+    for (var i = 0; i < as.length; i++) {
+        as[i].onmouseover = (function (b) {
+            return function () {
+                b.style.position = 'relative';
+                b.style.top = (2 - Math.random() * 4) + 'em';
+            };
+        }(as[i]));
+    }
+}());
+</script>
 </body>
 </html>

@spinor, on type behavior in JavaScript:

Prototype-based OO is pretty interesting. That said, orthogonally, type coercion is still a bad idea.

Type coercion is okay in some limited cases. Being able to write "You have " + n + " cows" for an integer n without having to explicitly convert it to a string first saves on obvious boilerplate. My primary issue with JavaScript’s coercion behavior is that it violates the principle of least surprise from here to next Sunday. (See my earlier post on “Wat”.)

The Surprisingly Elegant JavaScript Type Model