オブジェクトのコンストラクターで、いくつかのスパン タグを作成し、それらを同じオブジェクトのメソッドに参照する必要があります。
これが私のコードの例です:
$(document).ready(function(){
var slider = new myObject("name");
});
function myObject(data){
this.name = data;
//Add a span tag, and the onclick must refer to the object's method
$("body").append("<span>Test</span>");
$("span").click(function(){
myMethod(); //I want to exec the method of the current object
});
this.myMethod = myMethod;
function myMethod(){
alert(this.name); //This show undefined
}
}
このコードではメソッドが呼び出されますが、オブジェクトへの参照ではありません (this.name show undefined) どうすれば解決できますか?
どうもありがとう!