2013-04-09 37 views
0

我有這樣調試JavaScript寫在對象字面模式?

var innerPage = { 

/* declare vars, cache selectors */ 
leftWidth   : $("#episodes-nav").width(), 
right    : $("#episodes-right"), 
theWindow   : $(window), 
heroImageHolder  : $("#hero-image-holder"), 
heroImage   : $("#hero-image"), 

whiteOverlay  : $("#white-overlay"), 
tilesContainer  : $("#tiles-container"), 


heroPercentToShow : 0.6, 
// heroHolderWidth  : this.heroImageHolder.width(), 
// heroHolderHeight : this.heroImageHolder.height(), 

heroImgRealW  : null, 
heroImgRealH  : null, 

/* init */ 
init    : function(){ 
    var that = this; 
    this.heroImage.on('load', function(){ 
     // image loaded .. do something 
     that.heroImgRealW = this.naturalWidth; 
     that.heroImgRealH = this.naturalHeight; 
     that.fitHeroImage(); 

     that.buildInnerBlocks(); 
    }); 

}, 


fitHeroImage  : function(){ 

    var desiredWidthToFit = this.heroPercentToShow * this.heroNaturalW; 
    var scaleRatio = this.heroViewportWidth/desiredWidthToFit; 
    //trace(scaleRatio); 

    this.heroImage.width(this.heroImage.width() * scaleRatio); 
    var offsetSides = (600 -this.heroImage.width())/2; 
    var offsetTop = (containerHeight -this.heroImage.height())/2; 
    //trace("top"+offsetTop); 
    this.heroImage.css("left", offsetSides); 
    this.heroImage.css("top", offsetTop); 

    this.heroImage.height(this.heroImage.height() * scaleRatio); 
}, 

/* destroy */ 
destroy    : function(){ 

}, 

/* sizeChildren */ 
sizeChildren  : function(){ 

    this.right.width(this.theWindow.width() - this.leftWidth); 
    this.whiteOverlay.width(this.right.width() - this.heroImageHolder.width() +2000); 
    this.tilesContainer.width(this.whiteOverlay.width()); 

    this.fitHeroImage(); 

    //$("#tiles-container").empty(); 
} 


} 

一些代碼,當我設置的函數中的斷點或它們的內部,他們不被觸發(在Chrome測試)。我該如何解決這個問題?

+1

在代碼中添加'debugger;',看看是否有幫助。有時關閉瀏覽器並重新打開瀏覽器會使斷點出現奇蹟般的效果。 – epascarello 2013-04-09 17:47:36

+2

你是否期望在執行所述函數之前,它將存儲在對象中的函數內的斷點? – 2013-04-09 17:51:41

回答

0

當你調用這些函數時,你的函數中的斷點會觸發,但是你應該能夠在你的innerPage被創建後設置一個斷點來檢查它。