473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

complex-syntax question...;)

I'm trying to implement a drag-n-drop script, found here..
http://cwdjr.net/test/newDrag.html

but it doesn't work quite the way I want it to (div to drag-n-drop moves
down the window when I first click on it..)

I'm having a hard time dealing with the code because I don't understand
some things about it..

first of all, in this script the function that does the drag-n-drop is
called thus:

return dragImg(this,event)

but function is declared thus:

function dragImg(div,evt,how) {

what is the 'how' for ?? it's not passed to function from function
call.. if I take it out from function declaration get error that 'how'
is undefined, but where IS it defined in this script (I mean what does
it evaluate to before code inside function starts running (I tested with
an alert in first line of function, it prints 'undefined', so I really
don't get this...)

also can someone pls explain syntax of these var declarations? (rather,
they're var initializations, right?)

how = how || "relative";

var mx = evt.pageX || evt.clientX + root.scrollLeft;

I've never seen vars initialized like this in JS (or any other language
for that matter) and can't look this up because don't even know what to
search for....:)

thank you very much...

Aug 13 '06 #1
2 1124


maya wrote:

function dragImg(div,evt,how) {
also can someone pls explain syntax of these var declarations? (rather,
they're var initializations, right?)

how = how || "relative";
how is the name of a parameter to the function dragImg it seems. When
the function is being called without passing in a third argument then
the value of how is the value undefined, the assignment
how = how || "relative"
then sets how to the string value "relative". That happends because ||
is the or operator in JavaScript which roughly looks at its first
operand (which is how having the value undefined), converts it to a
boolean (which in case of undefined yields false), then as the boolean
value is false looks at the second operand (which is the string
"relative") and returns its value.

<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Logical_Op erators>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '06 #2
maya wrote:
I'm having a hard time dealing with the code because I don't understand
some things about it..

first of all, in this script the function that does the drag-n-drop is
called thus:

return dragImg(this,event)

but function is declared thus:

function dragImg(div,evt,how) {
This is not a mystery. In JavaScript, missing parameters are given the default
value of undefined. This makes it easy to have optional parameters.
what is the 'how' for ?? it's not passed to function from function
call.. if I take it out from function declaration get error that 'how'
is undefined, but where IS it defined in this script (I mean what does
it evaluate to before code inside function starts running (I tested with
an alert in first line of function, it prints 'undefined', so I really
don't get this...)
how is defined in the function scope. If you delete it from the parameter list,
then obviously you will be introducing bugs.
also can someone pls explain syntax of these var declarations? (rather,
they're var initializations, right?)

how = how || "relative";

var mx = evt.pageX || evt.clientX + root.scrollLeft;

I've never seen vars initialized like this in JS (or any other language
for that matter) and can't look this up because don't even know what to
search for....:)
The logical OR operator can be used to fill in default values. If how is falsy
(which it will be if it has a value of undefined) then use 'relative' as the
default. If there isn't an evt.pageX value, then use evt.clientX + root.scrollLeft.

If you are going to be effective in this language, then you must be prepared to
understand how it works. Here is a place to start:
http://javascript.crockford.com/survey.html
Aug 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
21
by: Blair | last post by:
could someone PLEASE tell me why this doesn't work... ----------------------------------------- #include <complex> using namespace std; typedef complex<long double> cld; void main() { cld...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
7
by: Schüle Daniel | last post by:
Hello I am trying to customize the handling of complex numbers what I am missing is a builtin possibility to create complex numbers in polar coordinates so first I wrote a standalone function...
3
by: Russ | last post by:
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x 4.54 In other words, if I substitute a class...
12
by: vj | last post by:
Hi! I have a piece of code (shown below) involving complex numbers. The code is not running and giving error ("Invalid floating point operation" and "SQRT:Domain error"). I would be very...
2
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
1
by: perroe | last post by:
Hi I have a array of complex numbers that are stored in a simple double array. This is done since the array is part of an wrapper for an external C library, and the imaginary part of the first...
3
by: Klaas Vantournhout | last post by:
Hi all, I was wondering why there is one extra argument for the return values of complex functions. And why is this not the case with any other data type (except char) example : * In case...
9
by: void main | last post by:
I'm rather new to complex numbers in C and was wondering, how do I initialize a complex variable properly if the imaginary part is 0. I tried -------- #include <complex.h> float complex c...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.