He said that the code to be executed should be nested as shown in < script language="JavaScript1.2" >. But when asked to detect the javascript version, I got the following code:
var JS_ver = [];
(Number.prototype.toFixed)?JS_ver.push("1.5"):false;
([].indexOf && [].forEach)?JS_ver.push("1.6 "):false;
((function(){try {[a,b] = [0,1];return true;}catch(ex) {return false;}})())?JS_ver.push ("1.7"):false;
([].reduce && [].reduceRight && JSON)?JS_ver.push("1.8"):false;
("".trimLeft)?JS_ver.push( "1.8.1"):false;
JS_ver.supports = function()
{
if (arguments[0])
return (!!~this.join().indexOf(arguments [0] ",") ",");
else
return (this[this.length-1]);
}
alert("Latest Javascript version supported: " JS_ver.supports ());
alert("Support for version 1.7 : " JS_ver.supports("1.7"));
This script can not only detect the JavaScript version by detecting features, but also Check the features supported by a specific Javascript version.
We got the result, let’s take a look at how this system detects the javascript version, so we extracted the code (the extraction process was quite tangled) and got the following code:
Code implementation principle: according to different versions JavaScript has different support for some specific functions to determine its version. There is only one special treatment for version 1.4.