最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - creating closure compiler extern - Stack Overflow

programmeradmin5浏览0评论

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 pilation, the pilation 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?

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 pilation, the pilation 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?

Share Improve this question edited Jan 2 at 21:13 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Jan 14, 2014 at 19:28 frenchiefrenchie 52k117 gold badges319 silver badges526 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12 +200

Here you go:

  • How to Write Closure-piler 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.

So I've been struggling on and off with this question for a while and I've e up with a working solution for others who have a plug-in they want to use in their code with closure piler: 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.

发布评论

评论列表(0)

  1. 暂无评论