Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating closure compiler extern

I'm using a jQuery plug-in and Google Closure Compiler. The problem is that there's a bug in the plug-in when I add the URL of that plug-in into the compilation, the compilation fails. So I want to create an extern for that plug-in. Basically, I'm only using 1 object and 2 methods from the entire library; something like this:

var TheObject = $.plugin({...});

var SomeVar = TheObject.someName.otherName(SomeString, {

      prop1: [...],

      onError: function () {...}

});

TheObject.SomeMethod();

I looked at the doc on Google's website but it's written from a confusing "what-it-is" perspective and I need a simple "how-to" perspective on how to do this. What do I need to do to create an extern for what I have?

Thanks.

like image 338
frenchie Avatar asked Jan 14 '14 19:01

frenchie


People also ask

What are JavaScript externs?

Externs are files that look very much like normal JavaScript annotated for Closure Compiler. The main difference is that their contents are never printed as part of the compiled output, so none of the values are meaningful, only the names and types.


2 Answers

Here you go:

  • How to Write Closure-compiler Extern Files – Part 1 The Basics
  • jQuery Plugins and Closure-Compiler

I haven't had time to finish out the series on creating externs. If this isn't enough for your project, I'll revisit the topic.

like image 130
Chad Killingsworth Avatar answered Sep 16 '22 15:09

Chad Killingsworth


So I've been struggling on and off with this question for a while and I've come up with a working solution for others who have a plug-in they want to use in their code with closure compiler: instead of doing an extern, just use strings, like this:

var TheObject = $['plugin']({...});

var SomeVar = TheObject['someName']['otherName'](SomeString, {

      'prop1': [...],

      'onError': function () {...}  
});

TheObject['SomeMethod']();

That may not work for everybody but this worked for me and saved me a great deal of hassle in terms of writing an extern. I found the doc online to be very confusing: either written by techies who explain what things are, but now how to use them, or written in a professorial tone, with not many empirical examples. I hope this answer will help others.

like image 34
frenchie Avatar answered Sep 16 '22 15:09

frenchie