Hi,

> If you want to call a method of a CLASS
> then yes it will work because 'this' is then no longer tied to a
> specific OBJECT.

Yes, it is. It is tied to the "class object", which is the constructor 
function object in JavaScript:

function myWonderfullClass() {
        this.countme = ++myWonderfullClass.countme;
}
myWonderfullClass.countme = myWonderfulClass.prototype.countme = 0
myWonderfulClass.alertCount = myWonderfulClass.prototype.alertCount = 
function() {
        window.alert(this.countme);
};
function callMyFunction(f) { f(); }

// this will alert '0'
myWonderfullClass.alertCount();

myObject = new myWonderfullClass();
// this will alert '1'
myWonderfullClass.alertCount();
// this will alert '1'
myObject.alertCount();

// this will alert '', or 'undefined'
'callMyFunction(myWonderfulClass.alertCount);
// this will alert '', or 'undefined'
'callMyFunction(myObject.alertCount);

this.countme = 42;
// this will alert '42'
'callMyFunction(myWonderfulClass.alertCount);
// this will alert '42'
'callMyFunction(myObject.alertCount);

Christof

Reply via email to