Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
这是一个运行时类型合约库,它采用一些类似于 Haskell 的语法:http://code.google。 com/p/ristretto-js。
This is a runtime type contracts library which takes on some Haskell like syntax: http://code.google.com/p/ristretto-js.
这个问题的实现给我留下了深刻的印象:
JavaScript 代码合约库?
示例:
I was pretty impressed by the implementation put together for this question:
JavaScript Code Contract Libraries?
Example:
为什么不自己创建一个库呢?
使用策略模式,您可以轻松地对特定值运行一系列方法。
这是一个半粗略的例子。这显然需要更多的错误处理和修改,但它为您可以构建的内容提供了一个想法。 http://jsfiddle.net/fBfgz/
Why not just roll a library yourself?
Using a strategy pattern, you can easily run a series of methods on a specific value.
Here is a semi-crude example. This obviously needs more error handling and modification, but it provides an idea for what you could build. http://jsfiddle.net/fBfgz/
我可能会使用 QUnit 进行通用 JavaScript 测试。另请查看 Tim Disney 的 contracts.js,它可能更适合您的用例。
I would probably use QUnit for general purpose javascript testing. Also check out Tim Disney's contracts.js, which may be more specific to your use case.
Sweet-contracts 正是您想要的。
Sweet-contracts 是一个需要 sweet.js 的模块,并使用宏将合约添加到语言中。这样你就不必使用现有的(通常是不足/低效的)语言结构来破解你的合约。
sweet.js 允许您创建可以模块化扩展语言的宏。 这篇博文很好地介绍了 sweet 和它的力量的宏。您可以在浏览器此地址中实时试用。
Sweet-contracts does exactly what you want.
Sweet-contracts is a module requiring sweet.js, and uses macros to add contracts right into the language. This way you don't have to hack your contracts using existing (and usually insufficient/inefficient) language constructs.
sweet.js allows you to create macros that can expand the language modularly. This blog post gives a great introduction to sweet and the power of macros. You can try it out live in your browser at this address.