私はテキストエディタでFireFox 11でJavaScriptを書いています。以下の場合、 "var n = this.val"は "undefined"になります。どのように元のクラスオブジェクトのローカル値を取得するには?jQuery.ajaxで "this.value"を取得する方法
<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var Test = {
val : 0,
begin: function(v){
this.val = v;
this.recieve();
},
complete: function(o){
var n = this.val; // undefined
},
recieve : function(){
$.ajax({
url : "http://www.yahoo.com/", // Dummy
type: "POST",
dataType: "json",
complete: this.complete,
timeout: 1000,
});
},
};
var c = Object(Test);
c.begin(10);
</script>
</body>
</html>
この場合、Test.valは上書きされます。 var c =オブジェクト(テスト); c.begin(10); var d =オブジェクト(テスト); d.begin(20); – Tank2005
私は自分の答えを更新しました。 – scessor
正常に動作します。ありがとうございました。 – Tank2005