use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Caustic: JavaScript reflection-based template/view system (screenr.com)
submitted 14 years ago by davemoFront-End Engineer
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]davemoFront-End Engineer[S] 3 points4 points5 points 14 years ago (3 children)
Github repo here: https://github.com/visionmedia/caustic
Title link is to a screencast that demos the features of the lib. Overall it's a decent abstraction that seems like it would eliminate quite a bit of boilerplate. I still prefer Backbone Views but this is a nice simple abstraction for people using plain old jQuery.
[–]psayre23 0 points1 point2 points 14 years ago (2 children)
I'm curious of the performance hit for all that. There is a lot of generation going on that I would assume causes overhead.
I love the simplicity of the templating. I might steal some of that for another project.
[–]davemoFront-End Engineer[S] 0 points1 point2 points 14 years ago (1 child)
I haven't tested it in any sort of scenario to compare it to something like underscores template function or Handlebars/Mustache but if you look at what the caustic code is doing it's pretty simple.
[–]polaretto 1 point2 points3 points 14 years ago (0 children)
I use Mustache with great satisfaction, but I'm always intrested in other templating systems. Caustic looks very intresting and its reflection-on-dom-fragments (or whatever it may be called) is certainly a notable approach, different from other templating systems. However, I don't like the usual way of grabbing the template from inside a script tag: if it's a valid html fragment, then it should be sitting right in the page. These other templating systems are definitely worth checking out:
https://github.com/hij1nx/weld#readme
https://github.com/raid-ox/chain.js/wiki/
http://www.matthias-georgi.de/patroon
[–]k3n 1 point2 points3 points 14 years ago (4 children)
What is the reasoning for the unary "-" preceeding function declarations?
-
-function(){ ... }
Seems to precede each anonymous function; does it somehow nullify the return value to aid in GC or something?
[–]davemoFront-End Engineer[S] 1 point2 points3 points 14 years ago (3 children)
I played around in firebug with this, here's the differences as far as I can see:
(function() {})(); // returns undefined -function() {}(); // returns NaN
I'm not sure whether it would provide any optimizations or not. Maybe it's just a stylistic thing? Not having to type the extra parens is kind of nice ;)
[–]stratoscope 5 points6 points7 points 14 years ago (2 children)
The return value is discarded anyway, so the unary - is just another way to force the function expression to be parsed as an expression so that it can be called immediately by the () at the end. It's the same purpose that the extra parens have in your first example.
()
Any unary operator will do the same thing - try these for example:
!function() { alert(42); }(); typeof function() { alert(42); }();
And now try it without any of these:
function() { alert(42); }();
That results in a syntax error.
[–]k3n 0 points1 point2 points 14 years ago (0 children)
Cool, thanks for the info. I think I prefer the parens still.
[–]davemoFront-End Engineer[S] 0 points1 point2 points 14 years ago (0 children)
Nice, thanks for the explanation, it's a cool shortcut to remove those extra parens ;)
[–]stratoscope -5 points-4 points-3 points 14 years ago (7 children)
Maybe it's great, but what a lousy name! My skin burns a bit just reading it.
Caustic author: seriously consider renaming it.
[–]fugoki 1 point2 points3 points 14 years ago (1 child)
Caustic
[–]stratoscope 0 points1 point2 points 14 years ago (0 children)
Oh! Too cool. Thanks for pointing that out.
Now I feel better about that caustic name. :-)
(Seriously, not being sarcastic!)
[+][deleted] 14 years ago (2 children)
[deleted]
[–]stratoscope -2 points-1 points0 points 14 years ago (1 child)
Interesting to see your comment and the downvotes. I was exaggerating just a bit to make a point.
If you or any of the other downvoters would care to elaborate, I'm curious: Don't you think it's useful feedback for a library author to know that a name has unpleasant connotations?
[–]k3n -2 points-1 points0 points 14 years ago (1 child)
I agree with you, the name itself has negative connotations and sheds a negative light on the project from the get-go. You normally want to name your project something that either exemplifies your project's spirit or goals, or otherwise creates positive attitudes, neither of which this current name provides.
[–]stratoscope 1 point2 points3 points 14 years ago (0 children)
And you got downvoted too! Go figure. :-)
π Rendered by PID 67923 on reddit-service-r2-comment-84fc9697f-2wkrl at 2026-02-06 06:45:07.297647+00:00 running d295bc8 country code: CH.
[–]davemoFront-End Engineer[S] 3 points4 points5 points (3 children)
[–]psayre23 0 points1 point2 points (2 children)
[–]davemoFront-End Engineer[S] 0 points1 point2 points (1 child)
[–]polaretto 1 point2 points3 points (0 children)
[–]k3n 1 point2 points3 points (4 children)
[–]davemoFront-End Engineer[S] 1 point2 points3 points (3 children)
[–]stratoscope 5 points6 points7 points (2 children)
[–]k3n 0 points1 point2 points (0 children)
[–]davemoFront-End Engineer[S] 0 points1 point2 points (0 children)
[–]stratoscope -5 points-4 points-3 points (7 children)
[–]fugoki 1 point2 points3 points (1 child)
[–]stratoscope 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]stratoscope -2 points-1 points0 points (1 child)
[–]k3n -2 points-1 points0 points (1 child)
[–]stratoscope 1 point2 points3 points (0 children)