Saturday, March 22, 2008

javascript conditional function definition (c #ifdef ?)

C:


#ifdef MOZILLA_OS
#define _XHTML_
#endif

#ifdef _XHTML_
int print()
{
printf("<node />");
}
#endif

#ifndef _XHTML_
int print()
{
printf("<node></node>");
}
#endif



Javascript:


var OS="MOZILLA";
var XHTML;

if(OS=="MOZILLA")
{
XHTML=1;
} else {XHTML=0;};

if (XHTML)
{
function print() {document.write("<node />");};
} else {
function print() {document.write("<node></node>");};
};

No comments: