In the last line, how can I ensure that the "this" i'm referring to is the instantiated k8rModal object and NOT the object running the function?
For other items in the future I'll need to dynamically construct lambda functions as well. Is that possible WITHOUT a global variable?
function k8rModal(DOMnamespace){
var _ = this._ = DOMnamespace+"_"; // for DOM namespacing
this.tightWrap=1;
$('body').prepend('<div id="'+_+'stage"></div>');
this.stage = stage = $('#'+_+'stage');
stage.css({
'display':'none',
'width':'100%',
'height':'100%',
'color':'#333'
});
$('body').append('<div id="'+_+'slate"></div>');
this.slate = slate = $('#'+_+'slate');
slate.css({
'display':'none',
'width':'640px',
'height':'480px',
'color':'#eee'
});
$('body').delegate('.'+_+'caller','click',function(){
/* this... but not, this? */.appear();
});
}
k8rModal.prototype.appear = function(){
//make the modal box appear
}
thiseverywhere, just usevar that = this;at the top of your function and usethatfrom then on. So then in other scopes, they can still use their ownthisbut still reference the higherthisasthat.