Help Me Understand This

T

Trevor

I'd really appreciate it if someone could please help me understand the
code below. The only question I have about c_table() is about the t &&
range( 1 )... line; what does the t && part mean? The range() is a
textRange, so what does the t && mean?

I'm having a hard time figuring out how the range() function works. I
know it returns a textRange, but I'd like to understand how it works.

function c_table( e, v ) {
var t = showModalDialog( path + 'aiTable.html', v,
'scroll:0;help:0;status:0;dialogWidth:378px;dialogHeight:496px' );
active();
t && range( 1 ).pasteHTML( t );
}

function range( v ) {
var s = d.selection;
v && ( s.type != 'None' ) && s.clear();
var r = s.createRange();
r.parents = [];
if( s.type == 'Control' ) {
r.control = true;
r.parents.push( r.item(0) );
r.parent = r.item(0).parentElement;
} else {
r.control = false;
r.parent = r.parentElement();
}
while( r.parent && r.parent.id != 'aiEdit' ) {
r.parents.push( r.parent );
r.parent = r.parent.parentElement;
}
return r;
}

Your help is appreciated.

Trevor
 
J

james.r.carr

A dirty hack... if t is false, range( 1 ).pasteHTML( t ); doesn't
execute. Essentially, the genius who wrote this really meant:

if(t) { range( 1 ).pasteHTML( t );
 
P

pipe

t && range( 1 ).pasteHTML( t );

&& is the AND op, so, the coder uses short circuit evaluation, its a
shotrhand for

if(t){
range( 1 ).pasteHTML( t );
}

so, he detects that the funcion showModalDialog() returned something,
and if so, he calls pasteHTML


shotr circuit evaluation, as you already know, is used to parse
expressions, so

if( a || b || c || d || f ){do_something()}

if the JS engine sees that a is trus, it wont even look at b,c,d,f,
because it alreay knows that thats ( a || b || c || d || f ) true,
otoh,

a &&b &&c && xyz()

will execute xyz only when a, b and c are true.

hope it helps.

/f3l
http://www.geocities.com/kyoosho/
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top