TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: cofoja-like's contracts for Javascript - my Saturday afternoon project.

1 pointsby pretzelover 14 years ago

1 comment

pretzelover 14 years ago
I saw cofoja (<a href="http://code.google.com/p/cofoja/" rel="nofollow">http://code.google.com/p/cofoja/</a>) this afternoon, and realised it would be good to be able to code like that, but since I spend my days doing mostly Javascript I wouldn't get to use it. So I've basically just ported it across. It's just an afternoon's work so it's probably incredibly bug ridden - don't even consider thinking about using it for real production code!<p>There are some other libraries that do the same thing for Javascript, (<a href="http://www.cerny-online.com/cerny.js/" rel="nofollow">http://www.cerny-online.com/cerny.js/</a> <a href="http://weblogs.mozillazine.org/weirdal/archives/016921.html" rel="nofollow">http://weblogs.mozillazine.org/weirdal/archives/016921.html</a> and one also called jsContract (oops - - looks like I might have to change my name...) <a href="http://kinsey.no/projects/jsContract/" rel="nofollow">http://kinsey.no/projects/jsContract/</a>)<p>The difference with these is they all expect you to call a special library within your functions. My library takes the cofoja approach, where you keep your function the same, but wrap it up with annotations that specify the contracts. You can even turn contracts off completely, by setting a variable.<p>It has some tests there, but they aren't in jsUnit - I'll do that tomorrow. My next step is to put contracts on each of its own functions, just to prove it works.