I have an app using requirejs in a pretty simple method:
define([
'jquery',
'scriptone',
'scripttwo'
], function ($,scriptone,scripttwo) {
for(var i=0, max=arguments.length; i<max; i++){
// What is the name of the argument ????
}
});
In the for loop I would like to be able to retrieve the name of the argument so as this loops through it would return ‘$’, ‘scriptone’, ‘scripttwo’ …
I know this is ultimately a question about functions and arguments, just wondering if in the context of RequireJS there is a simple/good method to achieve this?
You should never ever need to know variable names at runtime. There’s something wrong with your application.
However, you can do it. Get a serialisation of the function, remove comments etc, and parse the arguments list. To get the function itself, you might use deprecated
arguments.calleebut better get a named reference to it. So you might end up with