gpt4 book ai didi

javascript - Closure compiler --debug 解决了我的bug

转载 作者:行者123 更新时间:2023-11-29 22:21:27 26 4
gpt4 key购买 nike

因此调试似乎有了新的含义,至少在 Closure Compiler 中是这样。

我有一个相当大的代码库,隔离问题是一项艰巨的任务。在我的入口点类中,我实例化了依赖项。其中之一未正确创建,对象存在,但未调用其构造函数。

这只发生在 ADVANCED 模式下,所以我尝试传递 --debug 标志,瞧,bug 消失了,构造函数被调用了。令人兴奋。我无法复制粘贴任何特定代码,您有什么建议?

/**
* @param {Element} parent
* @param {Object} opts
* @constructor
*/
ns.App = function(parent, opts) {
this.options = new ns.Options(opts || {});

var w = this.options.width || parent.offsetWidth;
var h = this.options.height || parent.offsetHeight;
this.view = new ns.AppView(w, h);
this.history = new ns.CommandManager();

// ....

// this one doesn't get called
this.amx_ = new ns.ActivityManager(this, this.options);
// this one does
this.output_ = new ns.Writer();
this.bind_();
};

最佳答案

使用 Closure 编译器,当调试标志使错误消失时,它通常表示您有重命名冲突。这可能是由于在外部定义的对象上设置属性,而该对象的属性未完全定义给编译器。编译器将您的属性重命名为与现有属性相同的名称。

这也可能是由于使用点分语法 (obj.prop) 引用属性而导致的,而该属性是使用引号语法 (obj['prop']) 声明的。根据定义,编译器将这些视为不同的属性。

确保打开 --warning_level VERBOSE 以帮助识别访问未定义的属性。尽管您的特定案例仍有可能无法识别。

关于javascript - Closure compiler --debug 解决了我的bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12215558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com