Ok take this function I have. This function is a method to a large
class I have written in JavaScript. I am using the prototype library
as a framework. You can see how I've had to cheat and use
classObject = this;
in order to preserve the 'this' scope to my class.
I've read the prototype API on bind and bindAsEventListener however
their usage just hasn't clicked in my head yet. I'm pretty sure the
answer lies within one of those functions but since I don't 100%
understand those 2, I can't really be sure.
What I want to do (and it's not required, I'm fine with using my
little cheat) is be able to capture the scope of the 'this' statement
to my class, and not within the scope of the prototype Event function
(if that makes sense).
Instead of doing
classObject.checkLength(element);
I'd like to do
this.checkLength(element);
I've been given a suggestion elsewhere but they limited me to one line
of code. I'd like to keep the function notation in the event I want to
execute multiple lines of code (elsewhere in my class actually does
run more than line of code)
attachAutoEvents: function (element) {
classObject = this;
if (element.id != "") {
switch (element.type) {
case "text":
case "password":
element = $(element.id);
if
(this.config.initiateAutoTab === true) {
//if
(element.readAttribute("onkeyup") == null) {
Event.observe(element, "keyup", function () {
classObject.checkLength(element);
});
//} else {}
} else {}
//if
(element.readAttribute("ondblclick") == null) {
Event.observe(element,
"dblclick", function () {
ZWHLINK(element.id);
});
//} else {}
break;
case "select-one":
element = $(element.id);
if
(this.config.initiateAutoTab === true) {
//if
(element.readAttribute("onchange") == null) {
Event.observe(element, "change", function () {
classObject.checkLength(element);
});
//} else {}
} else {}
break;
default:
break;
}
} else {}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---