So, I’m writing a new JavaScript algorithm, codenamed jBam (Javascript Browser Algorithm Module), and it is used to write an extremely simple way to detect a browser and it’s version. My main goal, is to be able to write this (with the library plugged in):
if(IE & version lessThan 9) {
// IE code for 8 and below
}
Right now, progress is going pretty good. I can write
if(browser == IE & version < 9)
So, back to my original question, the only thing I want to know is maybe someway set a variable for lessThan and set it equal to the symbol <. I’ve tried probably the most common remedy (var lessThan = <) but, of course, that’s a little too wishful, and a little too easy. And, as we all know, nothing is ever too easy. Any suggestions, maybe a JavaScript preserve I’m not thinking of?
I agree with @JCOC611, but it’s also possible that you make everything part of an object, and then make
versionan object as a property as well, where you can add a method calledlessThan, so you would have something like:And then use it like:
or
You’d have to add more things for “greater than” and “not equals” and whatnot, but that’s just to start it off.
I don’t exactly suggest this, because you can just as easily use normal Javascript operators to accomplish the same thing with less redundant code. This solution is more for a “readable” theme, but is in no way necessary or better.