473,473 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

a tough question

hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?
Jun 27 '08 #1
16 1332
Mr Shore <sh*********@gmail.comwrites:
hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #2
On Apr 14, 2:07 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?

No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
so what do you think of the prompt function?
Jun 27 '08 #3
Mr Shore <sh*********@gmail.comwrites:
>No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.

so what do you think of the prompt function?
It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt(data,function(value) {
// do stuff with value
});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #4
On Apr 14, 2:37 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
so what do you think of the prompt function?

It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt(data,function(value) {
// do stuff with value

});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
ok,seems i have to give up that idea
thanks for the quick reply
Jun 27 '08 #5
On Apr 14, 2:37 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
so what do you think of the prompt function?

It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt(data,function(value) {
// do stuff with value

});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}

t(b="hi");
which i meant to set second parameter of function t as "hi" but failed
Jun 27 '08 #6
Mr Shore <sh*********@gmail.comwrites:
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}

t(b="hi");
which i meant to set second parameter of function t as "hi" but failed
Javascript only does positional parameters. Just do

t(undefined,"hi");

or whatever you want to indicate "this parameter is useless" for the
first parameter. A possible downside to using undefined is that
undefined is a variable, and so can be set to a value that isn't
undefined. Anyone actually setting undefined to some defined value
should of course have their computer taken away.

See also: <http://developer.mozilla.org/en/docs/
Core_JavaScript_1.5_Reference:Functions:arguments>

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #7
VK
On Apr 13, 11:10 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Anyone actually setting undefined to some defined value
should of course have their computer taken away.
Thank you, bro! :-) :-|
Jun 27 '08 #8
On Apr 14, 3:10 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}
t(b="hi");
which i meant to set second parameter of function t as "hi" but failed

Javascript only does positional parameters. Just do

t(undefined,"hi");

or whatever you want to indicate "this parameter is useless" for the
first parameter. A possible downside to using undefined is that
undefined is a variable, and so can be set to a value that isn't
undefined. Anyone actually setting undefined to some defined value
should of course have their computer taken away.

See also: <http://developer.mozilla.org/en/docs/
Core_JavaScript_1.5_Reference:Functions:arguments>

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
thanks a lot
finally i tried your version,
which passed the function string then eval
Jun 27 '08 #9
Mr Shore <sh*********@gmail.comwrites:
On Apr 14, 3:10 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
thanks a lot
finally i tried your version,
which passed the function string then eval
That's not what my version was intended to do. Javascript has proper
function objects, meaning you can pass functions around and call them
without the error prone and slow use of eval().

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #10
On Apr 14, 5:25 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
On Apr 14, 3:10 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
thanks a lot
finally i tried your version,
which passed the function string then eval

That's not what my version was intended to do. Javascript has proper
function objects, meaning you can pass functions around and call them
without the error prone and slow use of eval().

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
but I don't know how to pass an executing function directly?
Jun 27 '08 #11
Mr Shore <sh*********@gmail.comwrites:
but I don't know how to pass an executing function directly?
I really hope that one day there will be a seriously good book about
javascript. Anyway:

function call_me_back(fun) {
var value = 42;
fun(value);
}

call_me_back(function(value) {
alert(value);
});

function cb(v) {
alert("V: "+v);
}

call_me_back(cb);
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #12
On Apr 14, 5:32 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
but I don't know how to pass an executing function directly?

I really hope that one day there will be a seriously good book about
javascript. Anyway:

function call_me_back(fun) {
var value = 42;
fun(value);

}

call_me_back(function(value) {
alert(value);

});

function cb(v) {
alert("V: "+v);

}

call_me_back(cb);

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
got it!
thanks a lot:)
Jun 27 '08 #13
On Apr 14, 5:42 am, Mr Shore <shore.cl...@gmail.comwrote:
On Apr 14, 5:32 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
but I don't know how to pass an executing function directly?
I really hope that one day there will be a seriously good book about
javascript. Anyway:
function call_me_back(fun) {
var value = 42;
fun(value);
}
call_me_back(function(value) {
alert(value);
});
function cb(v) {
alert("V: "+v);
}
call_me_back(cb);
--
Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/

got it!
thanks a lot:)
but now i think maybe i'll stick to the error prone though eval
version
because otherwise it'll be quite hard for me to make it work in all
occasions,eg. the variable num of parameters and so on
error prone or general
i choose the later
Jun 27 '08 #14
On Apr 14, 5:51 am, Mr Shore <shore.cl...@gmail.comwrote:
On Apr 14, 5:42 am, Mr Shore <shore.cl...@gmail.comwrote:
On Apr 14, 5:32 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Mr Shore <shore.cl...@gmail.comwrites:
but I don't know how to pass an executing function directly?
I really hope that one day there will be a seriously good book about
javascript. Anyway:
function call_me_back(fun) {
var value = 42;
fun(value);
}
call_me_back(function(value) {
alert(value);
});
function cb(v) {
alert("V: "+v);
}
call_me_back(cb);
--
Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/
got it!
thanks a lot:)

but now i think maybe i'll stick to the error prone though eval
version
because otherwise it'll be quite hard for me to make it work in all
occasions,eg. the variable num of parameters and so on
error prone or general
i choose the later
For variable numbers of parameters and named parameters the most
"natural" way I've found is to write functions that accept ONE
variable which is an object:

function doSomething(obj) {
var a = obj.a;
var b = obj.b;

alert(a+','+b);
}

doSomething({ a:100 });
doSomething({ b:'Hello' });
doSomething({
a:'Hi',
b:'Bye'
});
Jun 27 '08 #15
On Apr 13, 12:05 pm, Mr Shore <shore.cl...@gmail.comwrote:
hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?
This capability is called coroutines, and is a part of some functional
languages, and is a powerful level of expressibility, particularly in
UI applications. It is not natively supported in JavaScript (although
hidden under the covers of FF3's new synchronous XHR handler).
JavaScript Strands is a framework that provides this capability
through code compilation (which is definitely not everyone's cup of
tea):
http://www.xucia.com/page/Strands
Kris
Jun 27 '08 #16
In comp.lang.javascript message <87************@zeekat.nl>, Sun, 13 Apr
2008 21:10:40, Joost Diepenmaat <jo***@zeekat.nlposted:
>
or whatever you want to indicate "this parameter is useless" for the
first parameter. A possible downside to using undefined is that
undefined is a variable, and so can be set to a value that isn't
undefined. Anyone actually setting undefined to some defined value
should of course have their computer taken away.
However, var U apparently generates a known U whose value is
genuinely undefined even if the variable undefined has been defined.
One can use ==U or ===U, and get true if the LHS is not defined.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jun 27 '08 #17

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

Similar topics

13
by: Elaine | last post by:
This has to do with self-joins and includes a running balance problem. Is it possible to do this using SQL alone? Amortization schedule -------------------------- Givens: beginning balance,...
9
by: denis | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a ...
3
by: denis_browne | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a ...
12
by: Mr Shore | last post by:
how to do the follows in IE: there's page A with element a pop a new page B from script in A and append element a into B after closing page B put element a back into A 'IE' solution only
4
by: Jim Rutledge | last post by:
ok ok , anyone know anything on this tough question? How do you determine the length in seconds that a midi file is , or any audio file for that matter ?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.