私はJavaScriptにかなり慣れていないので、ばかげたエラーかもしれません。次のようなオブジェクトを作成しました。
function objA(){
this.prop1;
this.prop2;
this.prop3;
this.func1=function(){
alert('func1');
}
this.func2=function(){
alert('func2');
}
}
オブジェクトを渡したい関数があります:
var foo=new objA;
function test(foo){....}
問題は、test() を呼び出すと、objA (objA.func1 および objA.func2) の関数が実行されることです。objA のプロパティ値を取得したいだけです。別の関数と配列を使用し、配列に objA のプロパティを入力してから、配列を渡す必要があります。
var arrayA={}
function fillArray(data){
arrayA.prop1=data.prop1;
arrayA.prop2=data.prop2;
arrayA.prop3=data.prop3;
}
function test(arrayA){....}
それが唯一の方法ですか、それとも何か間違っていますか?