首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QtScript Javascript对象丢失属性

QtScript Javascript对象丢失属性
EN

Stack Overflow用户
提问于 2012-05-17 02:04:34
回答 1查看 379关注 0票数 0

我创建了一个QScriptEngine,并将QObject设置为具有一些信号/槽的全局对象。然后我加载一些脚本文件并将其传递给引擎(使用evaluate)。脚本创建一个对象,并将全局对象的一些信号连接到它的函数。

遗憾的是,脚本对象的属性(this.password)在其函数从singal调用时被清除(它是在evaluate过程中设置的,我检查了这一点)。

下面是脚本:

代码语言:javascript
复制
   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);
}

你知道为什么会发生这种情况吗?

问候本

EN

回答 1

Stack Overflow用户

发布于 2012-05-17 02:41:10

Javascript对象是通过引用传递的。您是否在调用chanservObject.auth之前修改了Bot.Password

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10624135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档