Search code examples
javascriptgoogle-closure-compilergoogle-closure

Closure Compiler externs for the Foundation CSS framework


I want to run the Closure Compiler on a JavaScript file that initiates plugins for the Foundation CSS framework. The Foundation initialization is simple:

$(document).foundation();

However, when I run the Closure Compiler with advanced optimizations, this gets compiled to $(document).f();.

How do I write an extern to tell the Closure Compiler to ignore $(document).foundation();?


Solution

  • I solved this by copying and modifying the $(document).ready() extern from the jQuery 1.9 externs.

    The original:

    /**
     * @param {function()} handler
     * @return {!jQuery}
     */
    jQuery.prototype.ready = function(handler) {};
    

    And the modified version:

    /**
     * @param {function()} handler
     * @return {!jQuery}
     */
    jQuery.prototype.foundation = function(handler) {};