オブジェクトをクリックした後、一部のデータを処理するために使用するオブジェクトがすべての値を失います。クロージャーが原因であることはわかっていますが、修正方法がわかりません。Js で OOP を使用するのは初めてです。
私のコードはこれです:
function control_hermes(){
this.url_base="http://domain.com";
this.action="";
this.set_id_to_update;
//private
function set_action(parameter_to_control){
this.action=parameter_to_control;
}
//private
function get_full_url(){
console.log(this.action); //undefined?????, should be the id of the button
console.log(this.url_base); //undefined?????, is on the top!!!
return this.url_base+"?"+this.action;
}
//public
this.execute_instruction=function(id_button){
set_action(id_button);
var url=get_full_url();
}
}//end class
//use class
var manager_hermes=new control_hermes();
jQuery('input').click(function(){
manager_hermes.execute_instruction(jQuery(this).attr("id"));
});