I have some code in which I reference methods within the same object by using this
. I have verified that this
refers to current object by using the code sample below.
In my situation I have similar code, but its with a lot of other third-party ASP.Net controls, which emit their own JavaScript. But in my situation, when I use the same approach if using this
, it never works since this
is pointing to 'Sys.UI.DomEvent`.
<!DOCTYPE html>
<html>
<body>
<p>Creating and using an object method.</p>
<p>An object method is a function definition, stored as a property value.</p>
<p id="demo"></p>
<script>
var person = {
firstName: "Sunil",
lastName : "Kumar",
id : 5566,
fullName : function fullName() {
return this.newName(this.firstName + " " + this.lastName);
},
newName : function newName( nm) {
return 'new ' + nm;
}
};
document.getElementById("demo").innerHTML = person.fullName();
</script>
</body>
</html>
The page in my situation results in an error and the error is as below.
I have similar code as above code snippet. My code looks like below. Also, the functions in object below are called when a button is clicked, and may be that's why this
is not refering to the object AutoSizedStandardDialogs
object. May be there is another way to refer to the object AutoSizedStandardDialogs
when a button is clicked!
var AutoSizedStandardDialogs = {
applyAutoSizeLogic: function applyAutoSizeLogic() {
//code omitted
},
radalert: function radalert() {
this.applyAutoSizeLogic();
//code omitted
}
}
Question: Why in my situation using this
is not working and how can I force this
to point to the object that is containing these functions?