Reputation: 3881
I am trying to annotate my Javascript properly in order to avoid Google Closure messing up with my variables.
I am wondering if it is possible to strongly type an anonymous function to make sure the parameters of the function (which are externs in my case) are not renamed.
Here is an illustration
/** externs.js where I define my externs */
/** @interface a Json object returned by the server */
function MyServerResult() {}
/** @type {boolean} */
MyServerResult.prototype.error;
and in another file compiled with externs.js
and jquery.js
as externs.
$.get("url.php", function(data) {alert(data.error;}, "json");
I am trying to make sure the anonymous function function(data)
has @type {function(MyServerResult)}
so error
is not renamed.
Can I do that directly or do I need to create a seperate function (that will probably be inlined by the compiler...)?
Upvotes: 0
Views: 692
Reputation: 3758
I believe you should be able to do:
/**
* @param {MyServerResult} data
*/
var callback = function(data) {
alert(data.error);
};
$.get("url.php", callback, "json");
Upvotes: 2