Snippets of the day – Saturday, May 3, 2014

Posted on Posted in Snippets

orange-multi-tool

Here are some of the most recently published snippets!

Typescript + underscore: serializing objects

This little example runs on node.js and assumes you have the typescript type-definition file in the types subdirectory.

The example defines two classes one representing a undergrad course in computer science and another one representing possible students for the course.

Few things are interesting here:
1 – the overloading of the toString() function so that our own version is called automatically
2 – the use of underscore .reduce to serialize the array
3 – the use of the constructor element to initialize Student instances
4 – the use of lambda expression

overall we have a mixed object oriented and functional language here

Open the snippet

Author:    micurs

Adding a row at the beginning of a HTML table

A table in the DOM has always a tbody element enclosing the existing table trows (tr). So, if you are using JQuery here is how you can add a new row at the beginning of a table

Open the snippet

Author:    micurs

Leave a Reply

Your email address will not be published. Required fields are marked *