Pass parameters to resize event function

I need to attach a function to the resize event, but it doesn't work if the function has parameters, it works if I execute the function inside an anonymous function, but then I'm not able to remove the listener as theirs no reference to it.

Here is my code:

addEvent(window, 'resize', self.center(e) ); // Doesn't work

addEvent(window, 'resize', function() { // Does work but can't remove the listener
    self.center(e);
});

'addEvent' is just a simple cross-browser event listener function. I don't get any errors, the event just doesn't fire.

No jQuery answers please.

Edit:

addEvent Function:

function addEvent(elem, event, fn) {
    if(elem.addEventListener) {
        elem.addEventListener(event, fn);
    } else {
        elem.attachEvent('on' + event, fn);
    }
}

Answers


Need Your Help

Can I give a Symfony 2 service the ability to read and write cookies?

php symfony2 cookies

I have a service that should be able to read and write cookies. To do that in a Symfony-like manner, the service must have access to the request and the response. I can imagine that it's possible t...

uisearchbar crashes after pressing cancel

ios cocoa-touch cocoa nsarray uisearchbar

My filteredContentForSearchText ignores predicate after user presses cancel on search bar in iOS.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.