2013-12-09 31 views
1

我是javascript的新手。我寫了一個小代碼。但它在控制檯中顯示上述錯誤。我不知道爲什麼。任何幫助,將不勝感激。 在此先感謝。Uncaught TypeError:對象沒有方法'sortContents'

<!DOCTYPE html> 
<html> 
<body> 

<h1>My First JavaScript</h1> 
<p>Click the button to display the date.</p> 
<p id="demo"></p> 

<button type="button" onclick="testing()">Try it</button> 

<script> 
function testing(){ 
    alert("testing"); 
    var x = responseAjax; 
    x.resultType = "albums"; 
    x.result = "hell owrld"; 
    x.destId = "songsBody1"; 
    x.sortContents(); 
} 
function responseAjax(){ 
    this.sortContents = function(){ 
    alert("this issor contentes"); alert(this.resultType); alert(this.result); alert(this.destId); 
    } 
} 
</script> 

</body> 
</html> 
+4

做'變種x =新responseAjax;''變種X = responseAjax;'會給你只是函數引用,但你要創建一個對象來代替。 – PSL

+0

謝謝。我忘了添加「新」關鍵字。 –

回答

3

製作的實例作爲

var x = new responseAjax(); 
相關問題