0

I would like to make my script more efficient and while looking at my script which is fairly large I realize that nT.dS[v] is repeated quite often. I've tried do redefine it in a couple of ways, but none have worked, so I was wondering if any of you would know a way.

I need the shortening to be global. As I'm demonstrating, value is already shortened (and works well), but maybe it can be combined in another shortening to include the form id nT, and the input id dS, as this is the center of attention in the program.

<script id="jsGlobals">
var v = 'value'; // [v]  - Global variable in HTML
...
...
...
</script>

<script id="jsCompute">
function compute(nT) {
var sTr = nT.dS[v];  // nT is formID and dS is inputID. [v] replaces .value
var q = sTr.toUpperCase();
    if(q == "1") nT.dS[v] = dS116[v] //dS116 in input
    if(q == "2") nT.dS[v] = dS117[v] //ds117 is input
else nT.dS[v] = eval(nT.dS[v]) ;
}

some other functions

some other functions
</script>
Blue
  • 22,608
  • 7
  • 62
  • 92
  • 2
    Re *"Hey guys (and girls) :)"* two things: 1. Please don't cast "girls" as second-class citizens by putting them in parentheses, it's a form of casual exclusion which is not useful. 2. We don't do "hi" and "thanks" on SO. – T.J. Crowder Jul 27 '16 at 08:49
  • It seems that your code currently works, and you are looking to improve it. Generally these questions are too opinionated for this site, but you might find better luck at [CodeReview.SE](//codereview.stackexchange.com/tour). Remember to read [their requirements](//codereview.stackexchange.com/help/on-topic) as they are a bit more strict than this site. – Blue Jul 27 '16 at 08:51
  • Please don't anwere my questions this way, T.J. I have better things to do than discussing guy in plural, non native english speaking and the lack of general courtesy. Personally I appreciate some general courtesy when people spends time answering, so unless it's in the rules here, don't remove or rewrite my questions to be impolite, and top it off by claiming I cast women as second class. Just don't. – André B-Solberg Jul 27 '16 at 13:48

1 Answers1

0

Ok, I haven't solved how to incorporate [v] (short for.value) combined with id globally in script, but shortening the double Id's to local scope worked fine and gives a 20% reduction. Just writing this for others that might find it useful.

So in short I can add a =nT.dS; after function start and then write: if(q == "1") a[v] = dS116[v] instead of: if(q == "1") nT.dS[v] = dS116[v] vanilla: if(q == "1") nT.dS.value = dS116.value

Why is this important? Well, basically you can add a million question and answeres in a single file, cross browser working, html5... and still stay below a megabyte or two. Build your own (fixed or input selecting) search engine without sql. Those 20% soon adds up to quite a lot of milliseconds of loading, and kilobytes in filesize storage.

text answer instead of a local stored user input answer (or robotic input) would look like this:

if(q == "test") a[v] = "Hell yeah! Love it!"

vanilla would look like this:

if(q =="test") nT.dS.value ="Hell yeah! Love it!"

and unless i can mix a[v] down to a letter, it doesn't get much more efficient.

Enjoy