<script>
var model;
$(document).ready(
function() {
console.log("Document ready invoked!!");
model = new ModelContainer({container:$('#containerX')[0]});
var that = model;
window.addEventListener( 'resize', that.update, false );
}
);
ModelContainer = function(param) {
this.containerID = param.container.id;
this.containerWidth = param.container.offsetWidth;
this.containerHeight = param.container.offsetHeight;
console.log("Container ID width and height :", this.containerID, this.containerWidth, this.containerHeight);
}
ModelContainer.prototype.update = function () {
console.log("Update called invoked");
this.containerWidth = $(this.containerID).offsetWidth;
this.containerHeight = $(this.containerID).offsetHeight;
console.log("Container ID width and height :", this.containerID, this.containerWidth, this.containerHeight);
}
</script>
我试图了解在更新方法中使用“那个”。this.containerId 未定义。任何有助于理解为什么从侦听器方法调用“that.update”失败的帮助将不胜感激。