如何告诉闭包编译器忽略代码
How do I tell the closure compiler to ignore code?
我决定在实现接口时需要一些东西来帮助我。所以我在闭包库的base.js文件中添加了这个函数。
/**
* Throws an error if the contructor does not implement all the methods from
* the interface constructor.
*
* @param {Function} ctor Child class.
* @param {Function} interfaceCtor class.
*/
goog.implements = function (ctor, interfaceCtor) {
if (! (ctor && interfaceCtor))
throw "Constructor not supplied, are you missing a require?";
window.setTimeout(function(){
// Wait until current code block has executed, this is so
// we can declare implements under the constructor, for readability,
// before the methods have been declared.
for (var method in interfaceCtor.prototype) {
if (interfaceCtor.prototype.hasOwnProperty(method)
&& ctor.prototype[method] == undefined) {
throw "Constructor does not implement interface";
}
}
}, 4);
};
现在,如果我声明我的类实现了一个接口,但没有实现接口的所有方法,这个函数将抛出一个错误。从最终用户的角度来看,这绝对没有好处,它只是一个很好的补充,可以帮助开发人员。因此,当闭包编译器看到下面的行时,我该如何告诉它忽略它?
goog.implements(myClass, fooInterface);
有可能吗?
这取决于您所说的忽略是什么意思。你想让它什么都不编译,这样它就只能在未编译的代码中工作吗?如果是这样,您可以使用标准的@define值之一:
goog.implements = function (ctor, interfaceCtor) {
if (!COMPILED) {
...
}
};
或者仅当粘稠时。调试已启用:
goog.implements = function (ctor, interfaceCtor) {
if (goog.DEBUG) {
...
}
};
如果这些不合适,你可以自己定义。
或者你的意思完全是别的?
相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用Google闭包编译器调试代码删除
- 闭包编译器将't关闭可疑代码警告
- 使用闭包编译器简单优化从函数内部删除调试代码
- 使用闭包编译器编写更好的面向对象JavaScript完整示例代码
- 使用闭包编译器缩小包含 Jinja2 表达式的 JavaScript 代码
- 闭包编译器缩小代码中 (0, obj.method)(param1, param2) 的目的
- 在应用程序代码上运行Google Closure编译器后,更新AngularJS模板HTML
- 如何告诉闭包编译器忽略代码
- Google闭包编译器不会移除带有@define注释的不可访问代码
- 是否可以将匿名函数标记为“实时代码”?这样闭包编译器就不会删除它
- javascript编译器中的死代码
- 谷歌闭包编译器-基于外部的死代码删除
- 如何防止JS代码被编译器解析/评估
- 是否有可能编译WebDriverJS没有最小化代码的谷歌闭包编译器
- 如何使用谷歌闭包编译器压缩代码可从外部脚本访问
- 本地代码Typescript编译器
- 什么是最生产级别的Haskell到JavaScript编译器,编写在浏览器中运行的代码
- 代码重构Java脚本编译器
- JS编译器,同时编写前端和后端代码