Top

  1. Simple metaprogramming example in JavaScript

    function DataViewer() {
        this.renderers = {};
        this.renderers.table = function(data) { ... };
        this.renderers.tree = function(data) { ... };
    }
    
    DataViewer.prototype.render = function(type, data) {
        if (!this.renderers.hasOwnProperty(type))
            throw('Unknown data type.');
        return this.renderers[type](data);
    }
    Language: JavaScript
    3 points by Igor submitted 683 days ago | 0 comments
  2. jQuery counter with closures

    function count(data) {
        var count = 0;
        jQuery.each(data, function() {
           count++;
        });
        return count;
    }
    Language: JavaScript
    2 points by Igor submitted 683 days ago | 2 comments