473,419 Members | 2,065 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,419 software developers and data experts.

data parameter in bind method jquery

oranoos3000
107 100+
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 4880
oranoos3000
107 100+
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 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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 100+
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
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...
1
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...
4
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...
1
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...
0
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...
2
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
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...
3
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
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...
0
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...
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...
0
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...
0
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...

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.