simiane
03/29/2022, 3:33 PM<cfscript>
myArray = ['foo','foo','foo','bar'];
myCriteria = 'bar';
filteredArray = myArray.filter(function(myArrayVal, criteria = myCriteria){
return Arguments.myArrayVal == Arguments.criteria;
});
writeDump(filteredArray);
</cfscript>
Myka Forrest
03/29/2022, 3:37 PMarray.filter()
is its index.Myka Forrest
03/29/2022, 3:38 PMfunction(myArrayVal, i,a,criteria = myCriteria)
?simiane
03/29/2022, 3:41 PMMyka Forrest
03/29/2022, 3:43 PMwebsolete
03/29/2022, 3:44 PMsimiane
03/29/2022, 3:44 PMsimiane
03/29/2022, 3:46 PMMyka Forrest
03/29/2022, 3:46 PMA closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function's scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
simiane
03/29/2022, 3:49 PMarguments
scope of the outer function, I could use something like outer.arguments.myvar
? That'd be super helpful.Myka Forrest
03/29/2022, 3:49 PMsimiane
03/29/2022, 3:52 PMsimiane
03/29/2022, 3:52 PMMyka Forrest
03/29/2022, 3:53 PMsimiane
03/29/2022, 3:54 PMaliaspooryorik
simiane
03/29/2022, 4:01 PMsimiane
03/29/2022, 4:03 PMsimiane
03/29/2022, 4:04 PMmyCriteria
value elsewhere, because in most cases it already exists my outer function's arguments scope. So I'd want to use myCriteria = Arguments.criteria
.simiane
03/29/2022, 4:05 PMaliaspooryorik
function(item [,index, array]){}
aliaspooryorik
aliaspooryorik
simiane
03/29/2022, 4:09 PMaliaspooryorik
aliaspooryorik
simiane
03/29/2022, 4:12 PMsimiane
03/29/2022, 4:12 PMaliaspooryorik
simiane
03/29/2022, 4:18 PMcreateFilter
function each time is similar to just pushing the criteria into the local scope, which I was trying to avoid... but I really like the code-zen of it, and I'd imagine it has better performance than searching the outer scope.simiane
03/29/2022, 4:18 PMaliaspooryorik
zackster
03/29/2022, 4:41 PMaliaspooryorik