So I have the following piece of code:
var structures = {
loginStructure : function(){
return structure = [
'<form name="',opts.formClass,'" class="',opts.formClass,'" method="post" action="#">',
'<fieldset class="',opts.fieldsWrapper,'">',
'<fieldset class="',opts.userWrapper,'">',
'<label for="',opts.userInt,'" class="',opts.userLbl,'"><img src="',opts.userIcon,'" alt="',opts.userName,'" /></label>',
'<input type="text" name="',opts.userInt,'" class="',opts.userInt,'" placeholder="',checkNameLenght(opts.userName,namesLenght.userNameLenght,16,'Username'),'" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.passWrapper,'">',
'<label for="',opts.passInt,'" class="',opts.passLbl,'"><img src="',opts.passIcon,'" alt="',opts.passName,'" /></label>',
'<input type="password" name="',opts.passInt,'" class="',opts.passInt,'" placeholder="',checkNameLenght(opts.passName,namesLenght.passNameLenght,16,'Password'),'" value="" autocomplete="off" />',
'</fieldset>',
'<fieldset class="',opts.btnWrapper,'">',
'<button type="submit" name="',opts.btnInt,'" class="',opts.btnInt,'">',checkNameLenght(opts.btnName,namesLenght.btnNameLenght,7,'Login'),'</button>',
'</fieldset>',
'</fieldset>',
'<div class="toogle-button">',
'<ul class="inside">',
'<li class="toogle"><a><img src="assets/gfx/toogle.png" alt="Back" /></a></li>',
'</ul>',
'</div>',
'</form>',
'<div class="toogle-buttons">',
'</div>'
];
}
}
This returns ( if I do console.log(structures.loginStructure) ) just a function(). Is there a way I can make it to return the actual array I have in there ?
The purpose of it would be to have multiple arrays defined as object keys, if it is possible to return such a thing, because it seems easier. Or is there a better way to do this ?
You want:
structures.loginStructureis simply just returning a reference to the function, instead of executing the function and returning its result. Add the()to the end of it to execute it and return its result.Alternatively, and maybe better, don’t write it as a function. Just declare
loginStructure: ['<form name.... Basically, just removefunction(){return structure =. A significant difference to note here is that any values of opts would be evaluated immediately, instead of deferred until later when then function would be executed – so please don’t blindly update your code to this.