By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Help Me Understand This

P: n/a
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;dialog Height: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

Dec 29 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 );

Dec 29 '05 #2

P: n/a
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/

Dec 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.