我创建了一个QScriptEngine,并将QObject设置为具有一些信号/槽的全局对象。然后我加载一些脚本文件并将其传递给引擎(使用evaluate)。脚本创建一个对象,并将全局对象的一些信号连接到它的函数。
遗憾的是,脚本对象的属性(this.password)在其函数从singal调用时被清除(它是在evaluate过程中设置的,我检查了这一点)。
下面是脚本:
function Chanserv(password) {
this.password = password;
// print("#### Constructor local: " + password + " / global: " + Bot.Password);
}
Chanserv.prototype.test = function() {
// print("This is a test function / " + Bot.Password + " / " + this.password);
}
Chanserv.prototype.auth = function() {
print("#### entered auth function! " + this.password);
// if (this.password && this.password.length > 0) {
if (Bot.Password && Bot.Password.length > 0) {
Bot.sendMessage("nickserv", "identify " + Bot.Password);
// print("Trying to authenticate with " + this.password);
}
else {
print("Bot.Password undefined.");
// print("this.password = " + this.password
// + ", this.password.length = " + (this.password.length > 0));
}
}
var chanservObject = new Chanserv(Bot.Password); // this.password gets set
chanservObject.test();
try {
Bot.joinedChannel.connect(chanservObject.auth); // this.password is empty when called...
Bot.joinedChannel.connect(chanservObject.test);
// Bot.connected.connect(chanserv.auth);
}
catch (e) {
print(e);
}你知道为什么会发生这种情况吗?
问候本
发布于 2012-05-17 02:41:10
Javascript对象是通过引用传递的。您是否在调用chanservObject.auth之前修改了Bot.Password
https://stackoverflow.com/questions/10624135
复制相似问题