i have a event bind function like this(though it is not so robust):
bind$=function( o,evt,fn,cb){
var aE='attachEvent ';
var aEL='addEventLi stener';
if(!o[aE]&&o[aEL]){
return o[aEL](evt,fn,!!cb);
}
return o[aE]('on'+evt,fn);
};
some usage like this:
bind$( /* o */ document, /* evt */ 'click', /* fn */ function(txt)
{alert(txt);} );
but how can I pass a parameter to the bound function "fn" ? 6 2075
On May 28, 10:57 am, Max <Maximus.Zh...@ gmail.comwrote:
i have a event bind function like this(though it is not so robust):
bind$=function( o,evt,fn,cb){
var aE='attachEvent ';
var aEL='addEventLi stener';
if(!o[aE]&&o[aEL]){
return o[aEL](evt,fn,!!cb);
}
return o[aE]('on'+evt,fn);
};
some usage like this:
bind$( /* o */ document, /* evt */ 'click', /* fn */ function(txt)
{alert(txt);} );
but how can I pass a parameter to the bound function "fn" ?
Simply define the "fn" argument as an anonymous function that
specifies inside of it all the special parameters or initialization
that you want.
For instance, if your actual event handler takes both the expected
"evt" parameter along with an additional "foo" parameter, then the
"fn" argument could be this:
function (evt) { myhandler(evt, "bar"); }
On 5ÔÂ29ÈÕ, ÉÏÎç8ʱ15·Ö, "david.karr " <davidmichaelk. ...@gmail.comwr ote:
On May 28, 10:57 am, Max <Maximus.Zh...@ gmail.comwrote:
i have a event bind function like this(though it is not so robust):
bind$=function( o,evt,fn,cb){
var aE='attachEvent ';
var aEL='addEventLi stener';
if(!o[aE]&&o[aEL]){
return o[aEL](evt,fn,!!cb);
}
return o[aE]('on'+evt,fn);
};
some usage like this:
bind$( /* o */ document, /* evt */ 'click', /* fn */ function(txt)
{alert(txt);} );
but how can I pass a parameter to the bound function "fn" ?
Simply define the "fn" argument as an anonymous function that
specifies inside of it all the special parameters or initialization
that you want.
For instance, if your actual event handler takes both the expected
"evt" parameter along with an additional "foo" parameter, then the
"fn" argument could be this:
function (evt) { myhandler(evt, "bar"); }
thanks for reply.
may be I didnt display my situation clearly.
my bind function goes :
under firefox it is supposed to be like
document.addEve ntListener( 'click', function(txt){a lert(txt);} ,
false );
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
but I found problem when trying to transfer a parameter to the one
argument txt.
On May 29, 4:56 pm, Max <Maximus.Zh...@ gmail.comwrote:
On 5ÔÂ29ÈÕ, ÉÏÎç8ʱ15·Ö, "david.karr " <davidmichaelk. ..@gmail.comwro te:
On May 28, 10:57 am, Max <Maximus.Zh...@ gmail.comwrote:
i have a event bind function like this(though it is not so robust):
bind$=function( o,evt,fn,cb){
var aE='attachEvent ';
var aEL='addEventLi stener';
if(!o[aE]&&o[aEL]){
return o[aEL](evt,fn,!!cb);
}
return o[aE]('on'+evt,fn);
};
some usage like this:
bind$( /* o */ document, /* evt */ 'click', /* fn */ function(txt)
{alert(txt);} );
but how can I pass a parameter to the bound function "fn" ?
Simply define the "fn" argument as an anonymous function that
specifies inside of it all the special parameters or initialization
that you want.
For instance, if your actual event handler takes both the expected
"evt" parameter along with an additional "foo" parameter, then the
"fn" argument could be this:
function (evt) { myhandler(evt, "bar"); }
thanks for reply.
may be I didnt display my situation clearly.
my bind function goes :
under firefox it is supposed to be like
document.addEve ntListener( 'click', function(txt){a lert(txt);} ,
false );
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
but I found problem when trying to transfer a parameter to the one
argument txt.
On event listener call there are two "persistent " objects available:
1) the bound HTML element referred by "this"
2) the event handler referred by "arguments.call ee"
The first one can be used to store element-specific extra info. There
is also Function constructor - this is what I am using most often -
and closures which is an awful way IMO to use for identical event
handlers.
-- Option 1 --
refHtmlElement.
addEventListene r('click',
new Function(txt, functionBody),
false);
-- Option 2 --
refHtmlElement.
addEventListene r('click',
myFunction,
false);
refHtmlElement. args = {
'txt' : txt
};
and then later
function myFunction(evt) {
var txt = this.args.txt;
// ...
}
On 5ÔÂ29ÈÕ, ÏÂÎç9ʱ40·Ö, VK <schools_r...@y ahoo.com>wrote:
On May 29, 4:56 pm, Max <Maximus.Zh...@ gmail.comwrote:
On 5ÔÂ29ÈÕ, ÉÏÎç8ʱ15·Ö, "david.karr " <davidmichaelk. ..@gmail.comwro te:
On May 28, 10:57 am, Max <Maximus.Zh...@ gmail.comwrote:
i have a event bind function like this(though it is not so robust):
bind$=function( o,evt,fn,cb){
var aE='attachEvent ';
var aEL='addEventLi stener';
if(!o[aE]&&o[aEL]){
return o[aEL](evt,fn,!!cb);
}
return o[aE]('on'+evt,fn);
};
some usage like this:
bind$( /* o */ document, /* evt */ 'click', /* fn */ function(txt)
{alert(txt);} );
but how can I pass a parameter to the bound function "fn" ?
Simply define the "fn" argument as an anonymous function that
specifies inside of it all the special parameters or initialization
that you want.
For instance, if your actual event handler takes both the expected
"evt" parameter along with an additional "foo" parameter, then the
"fn" argument could be this:
function (evt) { myhandler(evt, "bar"); }
thanks for reply.
may be I didnt display my situation clearly.
my bind function goes :
under firefox it is supposed to be like
document.addEve ntListener( 'click', function(txt){a lert(txt);} ,
false );
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
but I found problem when trying to transfer a parameter to the one
argument txt.
On event listener call there are two "persistent " objects available:
1) the bound HTML element referred by "this"
2) the event handler referred by "arguments.call ee"
The first one can be used to store element-specific extra info. There
is also Function constructor - this is what I am using most often -
and closures which is an awful way IMO to use for identical event
handlers.
-- Option 1 --
refHtmlElement.
addEventListene r('click',
new Function(txt, functionBody),
false);
-- Option 2 --
refHtmlElement.
addEventListene r('click',
myFunction,
false);
refHtmlElement. args = {
'txt' : txt
};
and then later
function myFunction(evt) {
var txt = this.args.txt;
// ...
}
thanks VK
I was testing.....
but if the addEventListene r is used in some class and the
refHtmlElement should be document, then the way in option2 you
mentioned just not work.
class like:
idle=function(c allback){
this.starttime= new Date();
this.bound=fals e;
this.fn=callbac k;
this.reset=func tion(){
this.starttime= new Date();
};
this.init=funct ion(){
if(!this.bound) {
document.
addEventListene r('mousemove',
this.reset,
false);
this.bound=true ;
}
var secs=((new Date())-this.starttime)/1000;
if( secs % 59 == 0 ) {
this.fn();
}
}
....
};
....
/*
myidle=new idle(some function);
setInterval('my idle.init();',1 000);
*/
i want to indicate (by mousemove event) if the user
left the page for every 60 seconds, and
the function fn is tiggered.
and by reset the starttime to new Date() while the user is
still active on the page.(also by mousemove event)
but after event bound, in the this.reset function,
this is no more refer to the object i create (eg. myidle),
~~~~
but refer to document instead.
I should use document for the "refHtmlElement ", do you
think not?
any solutions?
how about this?
var idle=function(c allback){
var me=this;
* * * * me.starttime=ne w Date();
* * * * me.bound=false;
* * * * me.fn=callback;
* * * * me.reset=functi on(){
* * * * * * * * me.starttime=ne w Date();
* * * * * * * * };
* * * * me.init=functio n(){
* * * * * * * * if(!me.bound){
* * * * * * * * * * * * document.
* * * * * * * * * * * * addEventListene r('mousemove',
* * * * * * * * * * * * * * * * me.reset,
* * * * * * * * * * * * * * * * false);
* * * * * * * * * * * * me.bound=true;
* * * * * * * * }
* * * * * * * * var secs=((new Date())-me.starttime)/1000;
* * * * * * * * if( secs % 59 == 0 ) {
* * * * * * * * * * * * me.fn();
* * * * * * * * }
* * * * }
* * * * ....};
....
/*
myidle=new idle(some function);
setInterval('my idle.init();',1 000);
*/
On 5ÔÂ30ÈÕ, ÉÏÎç12ʱ07·Ö, RoLo <roloswo...@gma il.comwrote:
how about this?
var idle=function(c allback){
var me=this;
me.starttime=ne w Date();
me.bound=false;
me.fn=callback;
me.reset=functi on(){
me.starttime=ne w Date();
};
me.init=functio n(){
if(!me.bound){
document.
addEventListene r('mousemove',
me.reset,
false);
me.bound=true;
}
var secs=((new Date())-me.starttime)/1000;
if( secs % 59 == 0 ) {
me.fn();
}
}
....};
....
/*
myidle=new idle(some function);
setInterval('my idle.init();',1 000);
*/
Yeah, it works very nicely.
Thank you all very much! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: J.R. |
last post by:
Hi folks,
The python can only support passing value in function call (right?), I'm
wondering how to effectively pass a large parameter, such as a large list or
dictionary?
It could achieved by pointer in C++, is there such way in Python?
Thansk in advance.
J.R.
|
by: Mr A |
last post by:
Hi!
I've been thinking about passing parameteras using references instead
of pointers in order to emphasize that the parameter must be an
object.
Exemple:
void func(Objec& object); //object must be an object
instead of
|
by: Alan Silver |
last post by:
Hello,
I'm a bit surprised at the amount of boilerplate code required to do
standard data access in .NET and was looking for a way to improve
matters. In Classic ASP, I used to have a common function that was
included in all pages that took an SQL query and returned a disconnected
recordset. This meant that data access could be achieved in a single
line. I would like to do something similar in ASP.NET.
I know I could just duplicate...
|
by: Xiaoshen Li |
last post by:
Dear All,
I thought I understood using pointer variables as function parameters.
But I failed to understand why it is needed pass-by-reference of a
pointer variable.
To me, pointer variable is address variable, which holds the memory
address of the object. Using a pointer variable as a function parameter,
the function has the ability to CHANGE the object value pointed by the
pointer. Why needs pass by reference?
|
by: Ranginald |
last post by:
Hi,
I have a repeater based on a stored procedure. It pulls the following:
catDesc Image
The user sees the category description (catDesc) , and then clicks on
the image (Image) which is bound to the catID. This catID (@catID ---
an integer) is then to be passed to the next page, sculpture2.aspx for
use in a datagrid with a stored procedure.
| |
by: David++ |
last post by:
Hi folks,
I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.
The thing that troubles me about pass-by-reference into a WebService is that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type will
be...
|
by: Abhi |
last post by:
I wrote a function foo(int arr) and its prototype
is declared as foo(int arr); I modify the values of the array in the
function and the values are getting modified in the main array which
is passed also. I understand that this way of passing the array is by
value and if the prototype is declared as foo(int *), it is by
reference in which case the value if modified in the function will get
reflected in the main function as well. I dont...
|
by: venkatagmail |
last post by:
I have problem understanding pass by value and pass by reference and
want to how how they are or appear in the memory:
I had to get my basics right again. I create an array and try all
possible ways of passing an array. In the following code, fun1(int
a1) - same as fun1(int* a1) - where both are of the type passed by
reference. Inside this function, another pointer a1 is created whose
address &a1 is different from that of the passed...
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |