私は何をやっているのですか?同じラッピング変数/関数内で別の関数に変数を渡す方法を教えてください。JavaScriptを使用したときのtypedefエラー
例:
function customFunctionWrap(){
this.myVar1 = 0;
this.getCurrentPosition = function(){
if (navigation.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){});
}
},
this.doSomething = function(){ // Works
//Do something, return
this.callWithParams(); //Works
},
//If I remove passing in 'value1',calling it elsewhere works
this.doSomethingWithParams = function(value1){
//Use value1
//Return
},
this.callWithParams = function(){
var value1 = 'xyz'; //Is a variable that changes based on some DOM element values and is a dynamic DOM element
this.doSomethingWithParams(value1); //THROWS TYPEDEF ERROR: this.doSomethingWithParams is not a function
this.getCurrentPosition();
}
};
var local = new customFunctionWrap();
local.doSomething(); //WORKS
私はそれを行うための別の方法があります知っているし、その後、直接(customFunctionWrap.callWithParamsを使用)が、前者のアプローチが出erroringされる理由を理解しようとしています。
JSが見る何var customFunctionWrap = {
myVar1 : 0,
callWithParams : function(){
}
}
これは完全に間違っています。あなたは正確に何をしようとしていますか? –
呼び出し(引数)で渡された引数/パラメータが存在しないのに、call()が最初の例で機能する限り、編集された質問は機能します。なぜコール(引数)が機能しないのですか?私が正しく理解しようとしている部分であるIIFEではあまり明確ではありません。 –