syntax question

C

ctx2002

i was looking at prototype framework source code ,

Browser: {
IE: !!(window.attachEvent && !window.opera),
Opera: !!window.opera,
WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
navigator.userAgent.indexOf('KHTML') == -1
},

my question is what is that !! mean?

regards.
 
R

rf

i was looking at prototype framework source code ,

Browser: {
IE: !!(window.attachEvent && !window.opera),
Opera: !!window.opera,
WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
navigator.userAgent.indexOf('KHTML') == -1
},

my question is what is that !! mean?

A ! (not) inverts the (converted to boolean) value of what follows.

So !! converts anything to a boolean. ! (convert to boolean and invert) and
! again (invert it again).

Sloppy at the very least.

Doesn't matter anyway. What you quote above is browser sniffing which you
should not do. Do *NOT* use prototype, or any other "framework" out there as
a place to learn javascript.
 
B

Bruce Wisentaner

A ! (not) inverts the (converted to boolean) value of what follows.

So !! converts anything to a boolean. ! (convert to boolean and invert) and
! again (invert it again).

Sloppy at the very least.

Doesn't matter anyway. What you quote above is browser sniffing which you
should not do. Do *NOT* use prototype, or any other "framework" out there as
a place to learn javascript.

I consider !! to be idiomatic rather than sloppy.

---Bruce Wisentaner
 
J

John W. Kennedy

so why is framework a bad choice for learning javascript.

A) A well-written framework is much too complex for a beginner. Would
you try to learn C by studying the source code for device drivers?

B) Pretty much everyone seems to agree that prototype.js (I'm not
acquainted with it myself) is full of bad, bad, bad practices.
--
John W. Kennedy
"When a man contemplates forcing his own convictions down another man's
throat, he is contemplating both an unchristian act and an act of
treason to the United States."
-- Joy Davidman, "Smoke on the Mountain"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top