Hi,

I wanted to refactor some of my code in a nice Javascript 'class'.
The class has to register itself during initialization for several APE
events and commands

Sample class code:

var MyClass = new Class({
    Implements: [Options],

    options: {
        blablabla: 0
    },

    initialize: function(options) {
        this.setOptions(options);
        Ape.addEvent('adduser', this.onApeAddUser);
        Ape.registerCmd("my_command", true, this.onMyCommand);
    },

    onApeAddUser: function(params, infos) { Ape.log("onApeAddUser;
"+this.options.blablabla); },
    onMyCommand: function(params, infos) { Ape.log("onMyCommand:
"+this.options.blablabla); }
}

An instance of MyClass is created in 'global' scope like that:
var myInstance = new MyClass, { blablabla: 27 });

My problem is that in callback functions (onApeAddUser, onMyCommand),
the variable 'this' is not a reference to the instance of MyClass
(namely, 'myInstance'), but rather on the [object global].


1/ Is it the expected behavior for APE (If so, why ?) or a javascript
'standard behavior' (not the same as Java or C++ for example) ?

2/ Is there any convenient way to make 'this' points to the instance
holding the callback function ?
Or by default, any way to be able to pass the callback a reference to
the instance of MyClass ?

3/ I also noticed the same kind of behavior for several classes which
always return a reference on the Ape object that fired the event, not
the holder of the callback function (like callbacks of 'Ape.Mysql' and
'Ape.sockClient').


Thanks in advance.

Nouk²

-- 
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Reply via email to