Bug Tracker

Opened 7 years ago

Closed 7 years ago

#11803 closed bug (invalid)

IE7: Scope Binding inside Click Event

Reported by: stefanteofanovic@… Owned by: stefanteofanovic@…
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

Change History (3)

comment:1 Changed 7 years ago by Rick Waldron

Owner: set to stefanteofanovic@…
Status: newpending

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.

comment:2 Changed 7 years ago by stefanteofanovic@…

Status: pendingnew

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.

comment:3 Changed 7 years ago by scottgonzalez

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.