I want to be able to call info[‘id’] through the ajax…
var setEditor = function()
{
this.info = {
'id' : 1 // <--------------- i want this
};
var cardEditor = function()
{
var status = {
'touched' : false,
'id' : 0
};
card.children('input').bind('focusout', function() {
alert(this.info['id']); // <----------------- through this
$.ajax({
type : 'POST',
url : '../addcard',
data : 'name=John&location=Boston',
dataType : 'json',
success: function(msg){
$('#rec').html(msg);
}
});
});
};
};
set = new setEditor();
The problem is that
thisis a keyword that will refer to different things at different times. The trick is to create a new variablethatby assigningthisto it at a time whenthisis referring to what you want. Then it will be accessible to nested functions through lexical scoping. I generally do it once right at the top of my constructor functions.