How to pass externs file like underscore.js when using -m web --advanced

Hi,

I would like to know is there anyway that we can pass externs file to the closure compiler when publish web using command below?

cocos compile -p web -m release --advanced

I’m trying to compile with Parse javascript sdk which use underscore.js 1.4.4
https://www.parse.com/downloads/javascript/parse/latest/js

The code working fine when compile without --advanced

In the Closure Compiler FAQ

It suggest to use externs file which i found here but i don’t know how to pass in.

I have tried adding /** @expose */ to _. but it seem still having error

@ZippoLag @pandamicro

Do you have solution on this?

Thanks.

Hey, I’m sorry, I’ve been a bit busy and away from the forums lately.

Did you find a solution?

I actually ended up implementing my own methods in a helper class rather than using underscore.

@ZippoLag

Thanks for coming back forum to reply.

I’m using third party library which use underscore and i can’t simply reimplement them.

I do found solution to make it works but may not so efficient.

I adding this before every underscore function and it works.

/** @expose */
var each = _.each = _.forEach = function(obj, iterator, context) {

There is a function generating multiple functions

/*
  // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
  each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
    _['is' + name] = function(obj) {
      return toString.call(obj) == '[object ' + name + ']';
    };
  });
*/

I have to manually add those functions to make it work.

/** @expose */
_.isArguments = function(obj)
{
  return toString.call(obj) == '[object Arguments]';
};

:disappointed_relieved: I can’t imagine how much time that must’ve taken!

@ZippoLag

It do take some time but at least i make it work to run on web.
However, the underscore library in the parse library may not be the full version.

The easy way should be passing the extern file of underscore to the compiler but i can’t figure how to do that yet.