I had problem in my other code and huge, but I had made one prototype here,
this code is suppose to alert "hello John" instead of "hello undefined"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function callMethod(data, callback) {
return callback(data);
}
function client(divid) {
this.init = function () {
$(this.divid).click((function (context) {
return function () {
callMethod("hello ", context.method);
}
})(this));
}
this.divid = "#" + divid;
this.myname = "John";
this.method = function (d) {
alert(d + this.myname);
}
this.init();
}
$('document').ready(function () {
new client("mydiv");
});
</script>
</head>
<body>
<div id="mydiv">This is my div</div>
</body>
</html>
can some body point out me why I'm getting unexpected result here?
I'm getting unexpected result on
this.method = function (d) {
alert(d + this.myname);
}
this.myname suppose to return "John" here.
How to access class instance in event hanlder (JavaScript)? I'm getting help from above link, but I'm not being able to solve