jQuery Plugin Overwriting Parameters

Posted by Travis on Stack Overflow See other posts from Stack Overflow or by Travis
Published on 2010-03-13T08:35:10Z Indexed on 2010/03/13 8:45 UTC
Read the original article Hit count: 331

Hey Everyone,

This maybe a very mundane question, but this is the first jQuery plugin that I write and I'm a bit fuzzy on understanding the scope rules in Javascript.

I'm trying to write an simple jQuery plugin that wraps around the Stack Overflow API. I'm starting off by trying to work with the Flair API.

I wanted to make the plugin as configurable as possible so that you can easily pass it the domain and user id, and generate multiple Flairs.

    var superUser = $.jStackOverflow.flair({domain:"superuser.com", id: 30162, parentId:'#su-flair'});
    var stackOverflow = $.jStackOverflow.flair({domain:"stackoverflow.com", id: 55954, parentId:'#so-flair'});

The problem is, when it makes the second call, its somehow using the correct domain and id parameters, but the parentId field that it's using in the callback function to create the html, is using the first parameter.

You can see the plugin here and the html here

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript