calling another function within the same parent function
ok, maybe the title is a bit confusing, but I have this issue...
I'm making my own jsextension file for a package that I'm creating for a project, the thing is I'm having this error:js: joex-extensions.js: Javascript TypeError: this.isNumber is not a function, line 135
and the functions are like this:
var joex = new joexUtils();
joex.postln("JoeX jsexternals v0.66⍺(2020/04)");
function joexUtils(){
this.debug = 0;
// method to set parameter's function by variable name
this.parameterfy = (function () {
var pattern = /function[^(]*\(([^)]*)\)/;
return function (func) {
// fails horribly for parameterless functions ;)
var args = func.toString().match(pattern)[1].split(/,\s*/);
/*debug*/if(this.debug){this.postarr(args)};/*debug*/
return function() {
var named_params = arguments[arguments.length - 1];
if (typeof named_params === 'object') {
var params = [].slice.call(arguments, 0, -1);
if (params.length < args.length) {
for (var i = params.length, l = args.length; i < l; i++) {
params.push(named_params[args[i]]);
}
return func.apply(this, params);
}
}
return func.apply(null, arguments);
};
};
}());
...
// check if value is a number method
this.isNumber = function (v){
/*debug*/if(this.debug){this.postln("joex.isNumber debug:")};/*debug*/
var isNum = true;
if (!Array.isArray(v)){
isNum = (Number(v) < 0) || (Number(v) == 0) || (Number(v) > 0);
/*debug*/if(this.debug){this.postarr([v,isNum])};/*debug*/
}
else {
for (i = 0;i < v.length;i++){
isNum = isNum && (Number(v) < 0) || (Number(v) == 0) || (Number(v) > 0);
}
/*debug*/if(this.debug){this.postarr(v);this.postarr([isNum])};/*debug*/
}
return isNum;
}
...
//clip method
this.clip = this.parameterfy(function (value, min, max){
/*debug*/if(this.debug){this.postarr(["joex.clip debug:",this.isNumber(value),this.isNumber(min),this.isNumber(max)])};/*debug*/
if (this.isNumber(value) && this.isNumber(min) && this.isNumber(max)){
/*debug*/if(this.debug){this.postarr([value,min,max])};/*debug*/
return Math.min(Math.max(value,min),max);
}
else {
this.postln("Wrong parameter(s) given to joex.clip.");
return value;
}
});
...
}
so the thing is that I'm trying to use a function previously declared inside the same joexUtil function... There is no jsextension documentation so idk what is wrong, as far as I know that is possible if you declare the function previously... or am I misunderstanding it? please help!
everytime I call the function joex.clip I get the error...
PD: There are way more declarations there... the funcion this.parameterfy was copied from other place I don't remember right now...