spudly.shuoink.com

the best way to predict the future is to implement it

Entries Comments


Month: July, 2008

Date.add(), Date.subtract(), & Date.truncate()

4 July, 2008 (07:36) | JavaScript | 1 comment

If you’ve ever worked extensively with dates in javascript, you may have missed methods like these. These methods allow you to add or subtract time from a Date object. Truncate forces your date object into a specified precision. Here’s some examples:
var d = new Date();
//=> Fri Jul 04 2008 07:48:53 GMT-0600 (MDT)
d.add( “years”, 1 );
//=> [...]

assert for javascript

1 July, 2008 (20:26) | JavaScript | No comments

I was looking through a C++ book the other day and realized that javascript doesn’t have any functionality (that I know of at least) to perform assertions.
An assertion allows you to check in your script for things that should never happen, and throw an error if the thing that wasn’t supposed to happen happened. In [...]