|
List Info
Thread: object function as callback function
|
|
| object function as callback function |

|
2007-08-19 05:08:11 |
|
Hi all,
i am using cpaint now already for some time - and i am quit happy with it (good job - thanks for it).
Now i am working on a new project where i do need to create database objects (persons) on the fly...
For
this i have decieded to use Javascript Objects - so i build a
Javascript Object Person - which takes the PErsons data with the
constructor - and then calls the cpaint.call function with that data.
As callback function i do have specifid a function inside of my object.
I did thought that the function will get called within the object
scope. But it does seem to not be so. The callback seems to get called
outside the object scope.
Is it possible to get the callback function called within the object scope ?
Here is my example code: function Person(firstname, lastname, birthdate) { this.firstname = firstname; this.lastname = lastname; this.birthdate = birthdate; this.personid = null; // Will create the Person in the WHIDSYSTEM and set the person id this.cb_createPerson = function(result) { if (!result) { return null; } var person = result.getElementsByTagName('person'); if ((!person) || (person.length!=1)) { return; } person = person[0]; alert(this.firstname); // Will return undefined this.personid = person.getAttribute('personid'); }
// Do call the servers create person function cp.set_async(false); cp.call("helpers/cca.php", 'createPerson',this.cb_createPerson,sessionid); // Now we should have created the person so we have the personid // return to async operations cp.set_async(true); }
Thanks for hints
regards, Wolfgang |
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|