Fun Stuff > CLIKC

Need help (lots) with Javascript

<< < (9/13) > >>

Masterpiece:

--- Quote from: Stybar on 24 Aug 2013, 07:01 ---Why did you name a method isTalkingBonkers if your returning false when you ARE talking bonkers?

--- End quote ---

Oh. Damn. You're absolutely right. Semantics. Damn you.
I could make the code work but it would look ugly.


--- Quote from: Loki on 24 Aug 2013, 07:23 ---More importantly, why is isMasterpieceMakingSense not a function? :-D

--- End quote ---

Same as the above. OH WAIT THAT GAVE ME A GREAT IDEA!

Stybar:

--- Quote from: Loki on 24 Aug 2013, 07:23 ---More importantly, why is isMasterpieceMakingSense not a function? :-D

--- End quote ---

Didn't even see that. Damn.

Loki:
Technically speaking, it could still be a function, of course.

Stybar:
In Java, yes. But in Javascript?

Loki:
Everything is a variable in Javascript. Even functions.

Check this out:


--- Code: (Javascript) ---function isThisAFunction(){}

document.write(typeof isThisAFunction+"<br>");

if (isThisAFunction) {
document.write("isThisAFunction evaluates to true when passed to an if, because the if checks for existence"+"<br>");
}
else
{
document.write("isThisAFunction evaluates to false"+"<br>");
}

if (isThisAFunction==true) {
document.write("isThisAFunction is the same as true"+"<br>");
}
else
{
document.write("isThisAFunction is, however, not the same as true, even by lax comparison"+"<br>");
}
isThisAFunction = 5;
document.write(typeof isThisAFunction+"<br>");

--- End code ---

The result:

--- Quote ---function
isThisAFunction evaluates to true when passed to an if, because if checks for existence
isThisAFunction is, however, not the same as true, even by lax comparison
number
--- End quote ---

Also,

function isThisAFunction(){}

is functionally (:-D) equivalent to

isThisAFunction=function(){} 

:roll:

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version