我在做什么错误,以及如何将变量传递到同一个包装变量/函数内的不同函数。使用参数时出现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(),但我想明白为什么前一种方法示数出来。
var customFunctionWrap = {
myVar1 : 0,
callWithParams : function(){
}
}
这完全错了。你究竟想要做什么? –
只要没有在调用中传递参数/参数(参数),编辑问题就行不通,但call()在第一个示例中起作用。为什么呼叫(参数)不起作用。 IIFE不是很清楚,这是我试图弄清楚的部分。 –