Side navigation
#11803 closed bug (invalid)
Opened May 23, 2012 02:36PM UTC
Closed May 23, 2012 06:24PM UTC
IE7: Scope Binding inside Click Event
Reported by: | stefanteofanovic@hotmail.com | Owned by: | stefanteofanovic@hotmail.com |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hello,
Am having a class structured like this:
sClassName = function(par1, par2) {
this.init(par1, par2);
}
$.extend(sClassName.prototype, {
init: function(par1, par2){
doing something...
},
theFunction: function(){
doing something...
},
addEvent: function(){
$('somedomelement').click('click', function(){
this.theFunction();
}.bind(this)); //<- binding the scope
}
...
binding the scope "}.bind(this));" is working in FF and Chrome. My click event has scope over the instance which means i can call the function theFunction() from inside the click event.
How can i do this for IE7?
My class is manipulating the complexe object collections and not only DOM element. I need to have access to my functions from inside the click event. using "windows.classname.prototype.theFunction()..." may not work for multiple object instances.
Please help me
Regards,
Teofanovic Stefan
Attachments (0)
Change History (3)
Changed May 23, 2012 05:20PM UTC by comment:1
owner: | → stefanteofanovic@hotmail.com |
---|---|
status: | new → pending |
Changed May 23, 2012 05:58PM UTC by comment:2
status: | pending → new |
---|
Hello,
Thanks for your prompt answer. That looks like an interesting tool.
As requested i have created a small test case: http://jsfiddle.net/FrKyN/323/
This works on latest IE, FF and Chrome. Today i had problem with it using IE7 and i cant tell you if it works in here i a dont have IE7 installed at home.
Changed May 23, 2012 06:24PM UTC by comment:3
resolution: | → invalid |
---|---|
status: | new → closed |
You're using Function.prototype.bind
which doesn't exist in IE7. This is unrelated to jQuery. You should use jQuery.proxy()
instead. Please use the forums or StackOverflow for help.
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/
Open the link and click to "Fork" (in the top menu) to begin.