のonclickイベントでその変数を呼び出すしたいと思い、私は出力を得る私は、関数で変数を宣言していると私は
var config = function() {
this.page.url = "http://localhost/test/echowrite_code.html";
this.page.identifier = "this is the first post";
};
//i would like to get the config variable values in on click function
$('#sendComment').on('click', function(){
console.log("url:"+config.page.url);
console.log("identifier :"+config.page.identifier);
});
以下のような機能を持つ変数を宣言している:
url:undefined
identifier:undefined
が、予想される出力は次のようになります。
url:http://localhost/test/echowrite_code.html
identifier: this is the first post
しかし、私は
を期待していどのような値を取得しておりません
で、その後
私はあなたが取得しているどのような値1をexpecting_ていますどのような値を得ていないのです_but? 2.あなたはどのような価値を期待していますか? –
なぜ 'config'が機能していますか? – Andreas
「this.page」とは何でしょうか?関数で 'this'を使用したいのであれば、通常はオブジェクトまたはプロトタイプでなければなりません。 – Barmar