The JavaScript blog.


jquery plugins audio ideas sort

jQuery Roundup: Audio Sort, Improving fn.on with Generic Function Overloading

Posted on .

Note: You can send your plugins and articles in for review through our contact form.

Audio Sort

Audio Sort

I've had a difficult week of dealing with Windows 8, IE, and Visual Studio, so forgive me if I don't indulge myself a little bit by writing about Audio Sort (GitHub: skratchdot / audio-sort, License: MIT). It's written by "skratchdot" and is a visualisation of sort algorithms using jQuery, D3.js, subcollider.js, and Bootstrap.

When it comes to sort visualisations, I don't think anything will beat Quick-sort with Hungarian folk dance (thanks Matias) for sheer eccentricity, but it's a solid piece of work, and the inclusion of sound is somewhat idiosyncratic.

In a previous life I was also interested in audio programming, and subcollider.js is new to me. If you've ever seen SuperCollider but prefer JavaScript's syntax then you may enjoy it.

Improving fn.on with Generic Function Overloading

Sergii Kliuchnyk sent in js-fn-overloading:

I looked at the code for the Jquery.fn.on method and realized how many methods they have which take different argument types. They do many checks to change argument values to the right types. Here's my proposition for how to make the code clearer: js-fn-overloading and here's an example of what Jquery.fn.on looks like with it: jqueyr-on.js

The example in the readme is quite straightforward:

var obj = {  
  func: Overload('{Object|String}event, {String}[selector], {*}[data], {Function}fn', function(event, selector, data, fn){
    ok(this === obj);
    ok(typeof event === 'object' || typeof event === 'string');
    ok(typeof selector === 'undefined');
    ok(typeof data !== 'undefined');
    ok(typeof fn === 'function');

obj.func('', 1, function(){});  

The Overload function takes a configuration string which determines what types the overloaded methods should support, and how they should be mapped to arguments.