Q:

using this keyword in function javascript dojo toolkit

I have a javascript module in javascript dojo toolkit. But I have a problem about using this keyword.   
 define(["dojo/_base/declare","database/tool"],
        function (declare, databaseTool) {
            return declare(null, {
                person: null,
                spatialReference: null,

                constructor: function (parameters) {
                    this.person = parameters.person;                    
                },

                activatePerson: function () {

                    var db = new databaseTool();

                    var personOptions = {
                        "isActivated": true
                    };

                    var onActivated = function(result) {
                        var updatedPerson = result.person;
                        var oldPerson = this.person; //retuns <div id="person"/>
                    };

                    db.update(personOptions, onActivated );
                }
            });
        })

I want to use person object of module  in onActivated method via this keyword.
But this.person does not return javascript object. it returns <div id="person...>

A:

Dojo has a function for that called hitch() (from the dojo/_base/lang module). Your solution would be:
var onActivated = function(result) {
    var updatedPerson = result.person;
    var oldPerson = this.person; //retuns <div id="person"/>
};

db.update(personOptions, lang.hitch(this, onActivated) );

It accepts two parameters, the first one being the object used as scope (this) and the second one begin the function.

