To show how things can be made shorter:
As an example I'll take the
'file existing' routine shown by Chris Boulton.
code:
// Checking if a file exists:
function file_exists(file)
{
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
if(fileSys.FileExists(file))
{
return true;
}
else
{
return false;
}
}
If you use an IF THEN ELSE structure to check on a function which only returns true or false on its own, you can do:
code:
return fileSys.FileExists(file)
Since filesys is an object which you have defined before and since this is only used once, you don't specifically need it to be defined as a variable but you can use it directly:
code:
return new ActiveXObject("Scripting.FileSystemObject").FileExists(file)
All this makes that the function is reduced to only 1 line:
code:
function file_exists(file)
{
return new ActiveXObject("Scripting.FileSystemObject").FileExists(file);
}
-------------------------------
Various short functions derived from VB6:
see "
CookieRevised's reply to [I help them] VB2JS"