jQuery Tutorial plus Question:
Different ways of using $.connect function in jQuery?
Answers:
Answer #1The syntax of connect function is
$.connect(sourceObj/*object*/, sourceFunc/*string*/, callObj/*object*/, callFunc/*string or Func*/)
sourceObj(optional) is the object of the source function to which we want to connect
sourceFunc is the function name to which we want to connect
callObj(optional) is the object which we want to use for the handler function
callFunc is the function that we want to execute when sourceFunc is executed.
Here sourceObj, callObj are optional for the global functions.
suppose if your sourceFunc is global function then no need to pass the sourceObj or you can use null or self
suppose if your callObj is global function then no need to pass the callObj or you can use null or self
ex:
// fun1, fun2 are global functions
1. $.connect('fun1',fun2)
2. $.connect(null,'fun1',fun2)
3. $.connect(self,'fun1',fun2)
4. $.connect('fun1',null,fun2)
5. $.connect('fun1',self,fun2)
6. $.connect(self,'fun1',null,fun2)
$.connect(sourceObj/*object*/, sourceFunc/*string*/, callObj/*object*/, callFunc/*string or Func*/)
sourceObj(optional) is the object of the source function to which we want to connect
sourceFunc is the function name to which we want to connect
callObj(optional) is the object which we want to use for the handler function
callFunc is the function that we want to execute when sourceFunc is executed.
Here sourceObj, callObj are optional for the global functions.
suppose if your sourceFunc is global function then no need to pass the sourceObj or you can use null or self
suppose if your callObj is global function then no need to pass the callObj or you can use null or self
ex:
// fun1, fun2 are global functions
1. $.connect('fun1',fun2)
2. $.connect(null,'fun1',fun2)
3. $.connect(self,'fun1',fun2)
4. $.connect('fun1',null,fun2)
5. $.connect('fun1',self,fun2)
6. $.connect(self,'fun1',null,fun2)
Answer #2// fun1 is function of obj and fun2 is global function
1. $.connect(obj,'fun1',fun2)
2. $.connect(obj,'fun1',null,fun2)
3. $.connect(obj,'fun1',null,'fun2')
4. $.connect(obj,'fun1',self,fun2)
5. $.connect(obj,'fun1',self,'fun2')
// fun1 is global and fun2 is function of obj
1. $.connect(obj,'fun1',fun2)
2. $.connect(obj,'fun1',null,fun2)
3. $.connect(obj,'fun1',null,'fun2')
4. $.connect(obj,'fun1',self,fun2)
5. $.connect(obj,'fun1',self,'fun2')
// fun1 is function of obj1 and fun2 is function of obj2
1.$.connect(obj1,'fun1',obj2,obj.fun2)
2.$.connect(obj1,'fun1',obj2,'fun2')
1. $.connect(obj,'fun1',fun2)
2. $.connect(obj,'fun1',null,fun2)
3. $.connect(obj,'fun1',null,'fun2')
4. $.connect(obj,'fun1',self,fun2)
5. $.connect(obj,'fun1',self,'fun2')
// fun1 is global and fun2 is function of obj
1. $.connect(obj,'fun1',fun2)
2. $.connect(obj,'fun1',null,fun2)
3. $.connect(obj,'fun1',null,'fun2')
4. $.connect(obj,'fun1',self,fun2)
5. $.connect(obj,'fun1',self,'fun2')
// fun1 is function of obj1 and fun2 is function of obj2
1.$.connect(obj1,'fun1',obj2,obj.fun2)
2.$.connect(obj1,'fun1',obj2,'fun2')
Previous Question | Next Question |
How to use jQuery.connect? | Do you have plans for a new jQuery plug-in or something else we should look out for? Where to from here for the imgPreview plugin? |