473,796 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

data parameter in bind method jquery

oranoos3000
107 New Member
hi

i read about bind jqeury method

general syntax as follow as

bind(eventType, data,listener)
Establishes a function as the event handler for the specified event type on all elements in
the matched set.
Parameters

eventType :(String) Specifies the name of the event type for which the handler is to be

data: established. This event type can be namespaced with a suffix separated
from the event name with a period character.
(Object) Caller-supplied data that’s attached to the Event instance as a

listener : property named data for availability to the handler functions. If omitted, the
handler function can be specified as the second parameter.
(Function) The function that’s to be established as the event handler.

Returns
The wrapped set.


data prameter in above general syntax , how do i send this parameter, would please describe with an exapmle?

thanks alot for your help.
Nov 5 '10 #1
5 4902
oranoos3000
107 New Member
i read about data parameter in bind jquery method and that text is as follow as
"If you only ever use the type-specific event helpers (.click(), .load(), .change(), etc.), you're potentially missing out on a really handy feature of jQuery: bind data. Bind data is data associated with the bound handler function, available to every invocation of it, but not in any "normal" variable scope. It's kind of like currying, except with an event attribute instead of arguments. You declare bind data like this (as the optional middle parameter of the .bind() method):

Expand|Select|Wrap|Line Numbers
  1. jQuery("#selector").bind("click", {name: "barney"}, clickHandler);
And then you use it like this:

Expand|Select|Wrap|Line Numbers
  1. function clickHandler(e) {
  2.   alert(e.data.name);
  3. }
The 'e' variable is the standard jQuery event object passed to all event handler functions. The 'data' key within it contains the bind data created when the handler function was bound, if any. Even this simple case is potentially interesting because you're controlling the alert message at bind-time, not in the function itself, without the extra wrapper function you'd otherwise use:

Expand|Select|Wrap|Line Numbers
  1. jQuery("#selector").click(function() { clickHandler("barney")});
  2. function clickHandler(name) {
  3.   alert(name);
  4. }
But that's not the really useful bit. What you might not have noticed about the two examples is that in the first, the string "barney" is evaluated once (at bind time), but in the second it's evaluated every time the click event is dispatched. No big deal for a string, but for complex expressions that can create a performance issue. Since event handlers are typically executed more than once (and often a lot more than once), moving stuff out of the callback and into bind data can actually yield a noticeable difference in UI performance, as I learned this evening."

but ,where is used bind data to eventhanlder in time binding ?
Nov 5 '10 #2
Dormilich
8,658 Recognized Expert Moderator Expert
but ,where is used bind data to eventhanlder in time binding ?
you certainly have noticed that you (normally) can’t use parameters for event handler functions. thus you would need to use a closure to get those data to use (example 3). by using the bind() method you can pass those data to the event object (e) and get thesed data from the event object in your handler function (example 2) still retaining the easy standard event handler definition (example 1)
Nov 5 '10 #3
oranoos3000
107 New Member
hi
i understand your meaning but what is different between send static data while binding or while clicking an element

thanks alot for your help
Nov 5 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
the key difference is memory usage and that you don’t have to create a wrapper function each time. (and as explained) it may not be a lot of memory for a string, but objects may need much more.
Nov 5 '10 #5
oranoos3000
107 New Member
your meaning from object is data that is send in bind method or is function that send as parameter,
while i send data as an object more memory is used?

i'm confused , woule you please describe more.
thank alot
Nov 5 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6788
by: Bernie Yaeger | last post by:
Is there any way to get into the internals of the data adapter fill method such that I could know its progress status? For example, using the fill method to load a 40,000 row table takes just a few seconds, but using the fill method to load a 1.2 million row table takes more than a minute. I would like to do the latter with a progressbar, but I first have to know the progress of the fill method to do this - eg, what record is it up to...
1
3612
by: Will | last post by:
I have a web method in my web service that I would to have a command object passed in as a parameter. But when I compile the service I get the following error: You must implement the Add(System.Data.DataRowView) method on System.Data.DataView because it inherits from ICollection. If I replace the parameter's data type to a string, it compiles. Do web services only allow certain data types to be passed to web methods?
4
2350
by: Magy | last post by:
What would be the best way to execute a Oracle stored procedure that excepts several input paramters, through a web method in vb.net. What would be a good way to get to the web method, the Oracle stored procedure's definition; the name of the proc. and all of the parameter information such as name, value, type and value. I'm looking for the best method. Any ideas. Magy
1
1849
by: tony | last post by:
Hello! I just wonder if you out there have any your suggestion about this matter. I have a class in this class I have an ArrayList. In one instance method in this class I fill this ArrayList with values that have been reda from db. Now is it possible to say something about what is general best for this method.
0
813
by: thiago777 | last post by:
Hello all, I need to get data in my method through a parameter that gets the object of a "select" command from a database, so that I can later write the results of that select to a txt file. I was wondering if the correct way would be to pass the values by Reference or get a local copy from the object (ByVal). Anyone knows or had been through this ? any performance tips? thnks in advance!
2
3193
by: stepby | last post by:
Hi All, I would like to ask if I submit the data by the method="get", how can I handle the character (eg. &) without using the escape() or encodeURI() function ? Thanks and Regards, stepby
6
6284
by: pretzla | last post by:
I have a PL/SQL script where I load data from a stored procedure into bind variables. Then, I insert that data from the bind variables into an Oracle table with a simple insert statement. The execution of the stored procedure and the insert are in a FOR-LOOP. insert into ccd_t (acct_id, acct_seq_no, acct_btn) values
3
5452
by: fxeko | last post by:
Hi all... I have got a problem about passing data parameter in data report VB6 my problem: x= "admin" how to send value of x variabel to data report Thanks for your advabced
5
12868
sid0404
by: sid0404 | last post by:
Hi I am new to the visualstudio.net I am trying to develop an application which requires me to send data to a HTML webpage - http://patft.uspto.gov/netahtml/PTO/search-bool.html and the user sendsd the data to the webpage and receives the response to that particular values from the webpage. I am trying to use httpwebrequest for this purpose, but I am receiving errors, kindly let me know where I am going wrong. When I llok at the...
0
1364
by: shwethatj | last post by:
Can anyone please help me..... In Crystal Reports , how to access data using PULL method .. I have got a table in server explorer which has 3 got fields. But i dont know how to access it and generate a report. Actually i have first selected ASP.NET website with c# language , then i added a crystal report using add item in solution explorer . Later i had setup a new data connection in server explorer. The new connection has got a database...
0
9673
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, 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...
0
9525
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,...
0
10452
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, 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...
1
10169
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,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4115
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
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...

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.